Comparator<File> comparator = new Comparator<File>(){
public int compare(File file1, File file2){
DateForamt formatter = new SimpleDateFormat("MMddyyyy");
Date date1 = formatter.parse(file1.getName().substring(1));
Date date2 = formatter.parse(file2.getName().substring(1));
return date1.compareTo(date2);
}
}
File file = new File("/home/");
File[] files = file.listFiles();
Arrays.sort(files,comparator);
------解决方案--------------------
------解决方案-------------------- 一条语句里不好搞,写个小perl脚本轻松就搞定了
------解决方案-------------------- ls -a | sort -r | head -n 1
------解决方案-------------------- ls -A1rt | tail -n 1