Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Read file until EOF from offset each time

807580Apr 2 2010 — edited Apr 3 2010
Aight. I have a query regarding File I/O :
// Keep reading the file in a loop for some 100 seconds..
for (int x=0; x<100; x++) {
// Code for reading file - say readFile()
Thread.currentThread().sleep(1000); /* sleep for one second */
}
Now, I need to read a file (whose contents may keep changing over the course of the 100 seconds). Everytime I read the contents of the file, I need to get the new data (that's been added).
PS : No data will be deleted from the file. Data would only be added.

So, I assume I require to mark an offset and read from that offset until I encounter EOF. Every single time. How do I do this?

I'm using BufferedReader and there's this method :
public int read(char[] cbuf,
                int off,
                int len)
But, I do not know the len (length of characters) to be read each time. Remember, I need to read till EOF everytime. Someone suggested me to use the ready() method of BufferedReader, but I'm lost and do not know how to use it. Can someone put up a prototype example depicting this situation?

One other suggestion was not to use ready() but read until I encounter an Exception.. How do I use it if I want to go this way?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 1 2010
Added on Apr 2 2010
2 comments
394 views