I'm trying to monitor a file for changes in Java running on either Windows or Linux.
Currently I am looking into polling the last-modified property of the file instead of hooking into OS file events in an attempt to avoid dealing with smoothing over the API differences and handling asynchronous events.
I'm storing the result of new File("path").lastModified()
once I've processed the file and comparing new lastModified
results every x
seconds.
Can I rely on the fact that, assuming no foul play and someone manually modifying the timestamp, lastModified will always increase? The Java docs say that it is an offset from a GMT epoch, so presumably it won't go backwards even with timezone adjustments?
You can change the timestamp of a file to anything
http://unixhelp.ed.ac.uk/CGI/man-cgi?touch
If time is corrected using something like NTP, it can go backwards.
These situations are rare, and it might not be something you need to worry about.