• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java files  RSS feed

 
Chandramouli V.N
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have an error file that keeps updating itself.By updating what i mean is whenever there is an error the error is written into the file.I need to read the file and display the output.If it is a static file than it is easy.The data inside the file is dynamic.I need to display the latest contents of the file.Eg - First I read the 5 lines of the file then the error file is updated then i have to read the updated contents and display.
Does anyone have any idea about this.

Thanks

Mouli
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the old contents are replaced when a new error is added, you need to keep track of the last time you displayed it. Next time you check, only if its lastModifiedTime is larger than the value remembered, you display it again.

If the error messages are added at the end of the file, you need to keep track of how many lines of the files you have displyed so far. Next time you check, see if there are now more lines. If so, you only display the ones from the line you remembered to the last one.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can check the file size now & then and get the part of the file added since last time with a RandomAccessFile starting one byte after the old size. One of the sherrifs had a neater solution to this a while back but I can't recall it right now. Maybe he'll come through for us again.
 
jiju ka
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
implementing a FileChangeListener is one option
http://www.javaworld.com/javaworld/javatips/jw-javatip125.html

Another option
http://forum.java.sun.com/thread.jspa?threadID=306361&messageID=1241692

Alternatively lastModified() method in File can be used to identify whether a file is changed.
[ November 23, 2005: Message edited by: jiju ka ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!