2


I am continously reading a Logfile in realtime with a BufferedReader. This works pretty good. But every day there is a Log-rotate, which means my Logfile will be renamed and doesn't change anymore. A new Logfile will be created in the same place. Before I can change to that new Logfile, I need to finish reading the current one, which is no problem using BufferedReader, but how can I spot the filename has changed?

I tried calling file.getPath() and file.getAbsolutePath(), but this doesn't work, because the File-objects path is fixed after creation.

I also tried using the WatchService, but appending to the file causes a ENTRY_DELETE too. The resulting overead for checking if it was a rename is just to much.

Does anybody know a way to tell if the Logfile has been renamed?

tgr
  • 3,557
  • 4
  • 33
  • 63

1 Answers1

2

You might try JNotify. Does the job, though don't know of the resources it takes.

Big Bad Baerni
  • 996
  • 7
  • 21
  • Indeed that is what I am looking for, unfortunately it is not avaiable for older os. – tgr Feb 26 '14 at 12:36