Re: Reading a file that is being append too
From: kevinc (kevinc_at_elp.rr.com)
Date: 11/26/03
- Next message: Richard: "Object creation overhead"
- Previous message: Jorge Torres: "Reading a file that is being append too"
- In reply to: Jorge Torres: "Reading a file that is being append too"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 26 Nov 2003 16:23:10 GMT
You need to use the nio packages.
What you want is to establish a select channel on that file descriptor
to read from the file when data is available.
Jorge Torres wrote:
> I have an applet application that reads a file located at the server.
> Once I have establish the connection, I'm able read the contents of
> the file with out any problems, until I have reached the end of the
> file. Any new data that has been added to the file while the applet is
> running I'm unable to read.
>
> If I restart the applet again I can then see the data that was added.
>
> Can someone please help me with this problem?
> Thanks in advance!
>
> Here is my code...
>
> public void readFile(){
> ( new Thread() {
> public void run() {
> String line;
> URL url = null;
>
> try {
> url = new URL( getCodeBase(), FileToRead );
> }
> catch( MalformedURLException e ) {
> System.out.println( "Malformed URL " );
> stop();
> }
>
> try {
> InputStream in = url.openStream();
> BufferedReader dis = new BufferedReader( new
> InputStreamReader( in ) );
> buf = new StringBuffer();
>
> while( true ) {
> while( ( line = dis.readLine() ) != null ) {
> buf.append( line + "\n" );
> }
>
> // Load the file into the TextArea.
> ta.append( buf.toString() );
> Thread.currentThread().sleep( 5000 );
> }
> }
> catch( IOException e ) {}
> catch( InterruptedException ex ) {
> System.out.println( "InterruptedException!" );
> }
> }
> } ).start();
> }
- Next message: Richard: "Object creation overhead"
- Previous message: Jorge Torres: "Reading a file that is being append too"
- In reply to: Jorge Torres: "Reading a file that is being append too"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|