By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,032 Members | 825 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,032 IT Pros & Developers. It's quick & easy.

Reading a file that is being append too

P: n/a
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();
}
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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();
}


Jul 17 '05 #2

P: n/a
Thank You!

kevinc <ke****@elp.rr.com> wrote in message news:<Or******************@twister.austin.rr.com>. ..
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.

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.