我有一个代码可以列出目录中最新修改的文件。下面是我的代码:
//store the file to the list
List<File> list = new ArrayList<File>(Arrays.asList(store));
//combine all the file at main folder and sub folder
Object[] combine = list.toArray();
//sort the file according to the date
Arrays.sort(combine, new Comparator<Object>(){
public int compare(Object o1, Object o2){
return compare((File)o1, (File)o2);
}
public int compare( File f1, File f2){
long StartTime = f2.lastModified() - f1.lastModified();
if( StartTime > 0 ){
return 1;
}else if( StartTime < 0 ){
return -1;
}else {
return 0;
}
}
});
//get the file name that has latest modified date
files = ((File) combine[0]).getName();
//get the file date that has latest modified date
lastModifiedDate = new java.util.Date(((File)combine[0]).lastModified()).toString();
System.out.println("The latest modified file is : "+files);
System.out.println("The time for the latest modified's file is :");
System.out.println(lastModifiedDate);
当我修改目录中的文件并运行程序时,它可以列出我已修改的文件。但是当我修改目录中的1个以上文件并运行程序时,它只能显示具有最新修改时间的文件。我的问题是:如何在运行程序之前列出所有已修改的文件?