| Author |
File.lastModified() on windows vs linux
|
rajesh chalavadi
Greenhorn
Joined: Feb 13, 2008
Posts: 7
|
|
File.lastModified() javadoc says - A long value representing the time the file was last modified, measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970), or 0L if the file does not exist or if an I/O error occurs But this method is rounding off the value on the Linux, to its nearest second unlike windows. (for example if a file is modified at 1173423665215 msec, the above method is returning the value 1173423665000 on linux.) 1) Is there a way to avoid this rounding off on linux? OR 2) Are there any other methods available to get the file modified time in milliseconds. 3) Any method to know what is the precision of platform ( 1msec on windows and 1sec on linux.) Any help is highly appreciated.
|
 |
Stefan Wagner
Ranch Hand
Joined: Jun 02, 2003
Posts: 1923
|
|
Wikipedia tells me that for ext3 filesystems the timeresolution is 1s. http://en.wikipedia.org/wiki/Ext3 The same for reiserfs. http://en.wikipedia.org/wiki/Reiserfs For vfat, no information. ntfs: 100ns http://en.wikipedia.org/wiki/Ntfs Other documentations of the the filesystems should include that info as well. But: When I use while /mnt/c is a mounted ntfs volume, I get a nanotime, and which points to a reiserfs gives me an time in seconds, a small Java-test-program produces times of even granularity. Do you like to have an look into the sources, to find out why?
|
http://home.arcor.de/hirnstrom/bewerbung
|
 |
bart zagers
Ranch Hand
Joined: Feb 05, 2003
Posts: 234
|
|
The question is, do you really need millisecond precision? As far as I know, even Windows does not give you really millisecond precision, but only an "approximation".
|
 |
Stefan Wagner
Ranch Hand
Joined: Jun 02, 2003
Posts: 1923
|
|
Originally posted by bart zagers: The question is, do you really need millisecond precision? As far as I know, even Windows does not give you really millisecond precision, but only an "approximation".
It might not be of much relevance to Rajesh, while his question doesn't support that idea too much, but the java documentation claims:
Returns: A long value representing the time the file was last modified, measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970), or 0L if the file does not exist or if an I/O error occurs
which is simply wrong. It doesn't. java.io.File.lastModified itself calls java.io.FileSystem.getLastModifiedTime (File f) But I don't have the source of the native implementation. Perhaps I should  [ February 15, 2008: Message edited by: Stefan Wagner ]
|
 |
rajesh chalavadi
Greenhorn
Joined: Feb 13, 2008
Posts: 7
|
|
Thanks Stefan and bart for your replies. I am not worrying about millisecond precision. But looking for a way to get the same behavior across the platforms. As part of my requirements, am storing the file fetched time (System.currentTimeinMillis() ) and before updating the file, am comparing the fetched time with file.lastModifiedTime() to know whether the file got updated from the point we read it. But because of precision problem, the code behaves in different ways on different platforms!.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32833
|
|
|
time / 1000 * 1000?
|
 |
Stefan Wagner
Ranch Hand
Joined: Jun 02, 2003
Posts: 1923
|
|
|
if ((Math.abs (modified[0]-modified[1]) > 1000)
|
 |
 |
|
|
subject: File.lastModified() on windows vs linux
|
|
|