Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Tailing a file

 
Yaroslav Chinskiy
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at this link - maybe it will help:
http://forum.java.sun.com/read/16789542/q_ZINZ7rLChcAAgk6#LR
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic