我运行一些测试来证明一个概念,我刚才写的代码,发现一个奇怪的情况:奇怪的差异
public class Test {
public static void main(String[] args) {
Date now = new Date();
File file = new File("/root/batch-experiments/test.txt");
try {
file.createNewFile();
} catch (IOException e) {
System.out.println("cannot create file...");
}
System.out.println(MessageFormat.format("Checking File {0}! Last Modified time is {1}. Must be newer than {2}", file.getName(),
file.lastModified(), now.getTime()));
if (file.lastModified() >= now.getTime()) {
//ignore...
} else {
System.out.println(MessageFormat.format("File {0} is out of date and was ignored.", file));
}
}
}
输出是:
Checking File test.txt! Last Modified time is 1,253,187,650,000. Must be newer than 1,253,187,650,496
File /root/batch-experiments/test.txt is out of date and was ignored.
怎么可能? 新日期时间之后不应该是文件修改时间吗? 这发生在4/5次尝试中。
我在这里错过了什么?
任何方式来保证新的日期()比文件创建旧?
+1问题很有用,很好的解释。 – KLE 2009-09-17 12:08:34