Re: Reading a file that is being append too

From: kevinc (kevinc_at_elp.rr.com)
Date: 11/26/03


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();
> }



Relevant Pages

  • Multi-threaded access to a DatagramSocket
    ... I have a DatagramSocket in an applet which handles the RTCP channel of an RTP ... particularly efficient use of processor time. ...
    (comp.lang.java.programmer)
  • Re: Gnome Volume Control, not the panel applet
    ... > When I use bound keys to modify my volume up or down I see the volume ... > bar move up and down but there is no change to the volume of the audio I ... probably because the volume on the wrong channel is being changed. ... Try using the applet "Preferences" to choose what channel to control. ...
    (Debian-User)