Here is a simple code for getting the latest file from a given directory.
public final static File getLatestFile(String dirPath, FileFilter filter){ return getLatestFile(new File(dirPath).listFiles(filter)); } public final static File getLatestFile(File[] files){ long lastMod = 0; File latestFile = null; for (File file : files) { if(file.lastModified() >= lastMod) { latestFile = file; lastMod = file.lastModified(); } } return latestFile; }
コメント