How do I find the last modified file in a directory in java?
Your problem is similar to: How to get only 10 last modified files from directory using Java?
Just change the filter code to have only one File and the accept method should simply compare the two time stamps.
Untested code:
class TopFileFilter implements FileFilter {
File topFile;
public boolean accept(File newF) {
if(topFile == null)
topFile = newF;
else if(newF.lastModified()>topFile.lastModified())
topFile = newF;
return false;
}
}
Now, call dir.listFiles with an instance of this filter as argument. At the end, the filter.topFile is the last modified file.