Please help to find out whether a file was changed
Dear all,
I have a directory with different files, each file can be changed, how can I trigger the changes in a file and promt the user to update the document.
Something like out sync.
I think it could be a thred, which check the size of the file each five seconds for example. But I have seen programms, which did it immediately, as the used a hook or something like that, without any delay.
What is the common approach in java for this case?
Thanks in advance.
[499 byte] By [
flexeda] at [2007-11-27 11:16:10]

The java.io.File class has getLastModified() or something like that. You can use that, but it's possible for that to get updated without the file contents actually changing, so theoretically, you could get some false positives.
jverda at 2007-7-29 14:17:31 >

> The java.io.File class has getLastModified() or
> something like that. You can use that, but it's
> possible for that to get updated without the file
> contents actually changing, so theoretically, you
> could get some false positives.
Thank you for the answer.
If I will use this method, should I put it in thread? Or there is a better method to check for changes?
> If I will use this method, should I put it in thread?
> Or there is a better method to check for changes?
Using multithreading or not has nothing to do with "checking whether a file has been modified." You need to break down your problem into small, independent pieces.
* You want to know if a file has been modified. We briefly discussed that.
* You want to perform some task every five seconds. This has NOTHING to do with the above. You perform a periodic task using java.util.Timer and TimerTask.
Since those two things are completely independent of each other, get each one working on its own, without regard for the other. *THEN*, and only then, combine them into "check for file modification every 5 seconds."
jverda at 2007-7-29 14:17:31 >
