File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes Tailing  a file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Tailing  a file" Watch "Tailing  a file" New topic
Author

Tailing a file

Yaroslav Chinskiy
Ranch Hand

Joined: Jan 09, 2001
Posts: 147
What is the best way to tail a file?
I can write a thread that checks the file every 5sec and if new line is writen, then will notify, but how do you do it without a sleep.
Vector lines = new Vector();
try{
while(true){
try{
if ((record = logReader.readLine()) == null){
Thread.currentThread().sleep(5000);
}else{
if(record.length() == 0){
continue;
}
lines.addElement(record);

}
}catch(InterruptedException ie){
new ExceptionHandler(ie);
}catch(IOException ioe){
new ExceptionHandler(ioe);
}
}
}finally{
try{
logReader.close();
}catch(IOException ioe){}
}

Thank you.
Jim Baiter
Ranch Hand

Joined: Jan 05, 2001
Posts: 532
Take a look at this link - maybe it will help:
http://forum.java.sun.com/read/16789542/q_ZINZ7rLChcAAgk6#LR
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Tailing a file
 
Similar Threads
voice input
Sound Recording and Playing in Mobile Media API
Capture audio from Java ME application
lock and unlock
Check folder and start program execution further