/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package test; import java.io.File; import java.util.Arrays; import java.util.Comparator; /** * * @author Hansel */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here File file = new File("d:/axis2-1.5"); File[] fs = file.listFiles(); Arrays.sort(fs, new Main.CompratorByLastModified()); for (int i = 0; i < fs.length; i++) { System.out.println(fs[i].getName()); } } static class CompratorByLastModified implements Comparator<File> { public int compare(File f1, File f2) { long diff = f1.lastModified() - f2.lastModified(); if (diff > 0) { return 1; } else if (diff == 0) { return 0; } else { return -1; } } } }