473,321 Members | 1,708 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

Reading a file that is being append too

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
2 3025
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Satish Chimakurthi | last post by:
Hi all, This is in continuation of my email today regarding reading data files. I am stuck with one more problem now. Here are my two data files: a. fluid_grid.dat 1.00000000000000 ...
4
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # to open a file and write to file # do f=open('xfile.txt','w') # this creates a file "object" and name it f. # the second argument of open can be
9
by: Xarky | last post by:
Hi, I am writing an XML file in the following way. Now I need to read again that file to retrieve data such as Name and Age. Can someone help me out. Thanks in Advance ...
2
by: Wael Soliman | last post by:
hi all when i try to read from .xls file in .NET windows application it work correctly but when i try to use the same connection string in the asp.net i fail while the connection is the same i...
4
by: Brian Parker | last post by:
Here's a snippet of code I have: ============================================== DataSet ds = new DataSet(); string strXMLFileName = Path.GetTempFileName(); StreamWriter sw = File.AppendText(...
11
by: Girish Sahani | last post by:
I wrote the following code to concatenate every 2 keys of a dictionary and their corresponding values. e.g if i have tiDict1 = tiDict1 = {'a':,'b':} i should get tiDict2={'ab':} and similarly for...
59
by: psbasha | last post by:
Hi, I am here with placing the Sample code for reading the and Input data mentioned. Is there any best of reading the file?. Thanks in advance PSB Sampple1.txt Rect 1 1 2...
25
by: 7stud | last post by:
I can't break out of the for loop in this example: ------ import sys lst = for line in sys.stdin: lst.append(line) break
2
by: Logan Lee | last post by:
BACKGROUND READING: http://www.geocities.com/logan.lee30/a_crude_method_of_static_code_analysis.html http://www.geocities.com/logan.lee30/A_method_of_static_code_analysis.html Like this: ...
1
by: stevedub | last post by:
I am having some trouble configuring my array to read from a sequential file, and then calling on that to fill an array of interests. I think I have the class set up to read the file, but when I run...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.