import java.io.File;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;public class Demo13 {public static void main(String[] args) {List<File> list = FileUtils.getAllFiles("D:/IOTest/");// 按文件夹先显示的顺序:Collections.sort(list, new Comparator<File>() {@Overridepublic int compare(File o1, File o2) {return (o1.isDirectory() ? 1 : -1)-(o2.isDirectory() ? 1 : -1);}});// 按文件名称显示的顺序:Collections.sort(list, new Comparator<File>() {@Overridepublic int compare(File o1, File o2) {return (o1.getName()).compareTo(o2.getName());}});// 按文件大小的顺序:Collections.sort(list, new Comparator<File>() {@Overridepublic int compare(File o1, File o2) {return (int) (o1.length() - o2.length());}});for (File file : list) {System.out.println(file.getName());}}
}