This discussion is archived
2 Replies Latest reply: Apr 3, 2010 12:41 AM by masijade RSS

Read file until EOF from offset each time

807580 Newbie
Currently Being Moderated
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?