• Post Reply Bookmark Topic Watch Topic
  • New Topic

java.io.File  RSS feed

 
Jon Strayer
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
File has a couple of methods I'm interested in using to tell if another process is still writting to a file. One way to do that might be to call lastModified and see if the time returnd is close to now. Another would be to call length wait a while and call length again and see if it changed.
One problem with both of these is that the JavaDocs make no claims about when the return values are determined. For example, they could be set when the File is created. Or, File could go to the file system each time one of them is called.
Is this behavior specified anywhere?
 
Ta Ri Ki Sun
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jon Strayer:
File has a couple of methods I'm interested in using to tell if another process is still writting to a file. One way to do that might be to call lastModified and see if the time returnd is close to now. Another would be to call length wait a while and call length again and see if it changed.
One problem with both of these is that the JavaDocs make no claims about when the return values are determined. For example, they could be set when the File is created. Or, File could go to the file system each time one of them is called.
Is this behavior specified anywhere?

Hi Jon, lastModified is checked when the method is called, not when the File is created, to prove this to myself I ran a simple test that starts a thread, prints last modified, sleeps for a while, and prints again, while sleeping I changed the file and heres some of the output.

lastModified : Sun Apr 20 12:09:38 CAT 2003
lastModified : Mon Jul 14 11:08:35 CAT 2003

dont use length to check if the file changed, because you can change the file without changing length
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John,
Are FileChannels available to you?
M
 
Jon Strayer
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I could use a FileChannel. Thanks!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!