Apache Commons IO is a java library with simple IO utilities and filters.
This requires the library commons-io-2.1.jar to be in classpath.
The following example shows using FileFilterUtils.ageFileFilter() API.
It returns a filter that returns TRUE if the file's last modified time stamp is older than (before) the given
reference files's last modified time stamp.
/**
* @param args
* @throws IOException
*/ public static void main(String[] args) {
File directory = new File("C:/input");
File refFile = new File("C:/input/db.png");
//Files with modified date after the specified date
File[] files = directory.listFiles((FileFilter)
FileFilterUtils.ageFileFilter(refFile));
System.out.println("Ref file TS : " + new Date(refFile.lastModified()));
for (File file : files) {
System.out.println(file + " " + new Date(file.lastModified()));
}
}
}
It gives the following output,
Ref file TS : Sun Oct 23 23:54:09 IST 2011
C:\input\console.png Sun Oct 23 23:54:09 IST 2011
C:\input\db.png Sun Oct 23 23:54:09 IST 2011
C:\input\one.css Mon Oct 03 17:32:02 IST 2011
C:\input\three.css Mon Oct 03 17:32:02 IST 2011
C:\input\two.css Mon Oct 03 17:32:02 IST 2011