See, the problem is that in Java, we can get lastmodified date by filename.lastModified(). But in Windows, what is happening is that whenever a file is modifed, only that file's date and time are getting modified, not the whole folder's. So I want to know when was the last time even one single file was modified in that folder, using Java?
解决方案
Find the latest (largest) lastModified() in the directory's files, or if there are none use the directory's itself:
public static Date getLastModified(File directory) {
File[] files = directory.listFiles();
if (files.length == 0) return new Date(directory.lastModified());
Arrays.sort(files, new Comparator() {
public int compare(File o1, File o2) {
return new Long(o2.lastModified()).compareTo(o1.lastModified()); //latest 1st
}});
return new Date(files[0].lastModified());
}
FYI this code has been tested (and it works).