List<File> files = Arrays.asList(new File("文件目录").listFiles());
Collections.sort(files, new Comparator<File>(){
public int compare(File o1, File o2) {
if(o1.isDirectory() && o2.isFile())
return -1;
if(o1.isFile() && o2.isDirectory())
return 1;
return o1.getName().compareTo(o2.getName());
}
});
for(File f : files)
System.out.println(f.getName());
Collections.sort(files, new Comparator<File>(){
public int compare(File o1, File o2) {
if(o1.isDirectory() && o2.isFile())
return -1;
if(o1.isFile() && o2.isDirectory())
return 1;
return o1.getName().compareTo(o2.getName());
}
});
for(File f : files)
System.out.println(f.getName());