网站开发与移动开发

博客园 首页 新随笔 管理
static Comparator<File> comparator = new Comparator<File>() {
public int compare(File f1, File f2) {
if (f1 == null || f2 == null) {// 先比较null
if (f1 == null) {
{
return -1;
}
} else {
return 1;
}
} else {
if (f1.isDirectory() == true && f2.isDirectory() == true) { // 再比较文件夹
return f1.getName().compareToIgnoreCase(f2.getName());
} else {
if ((f1.isDirectory() && !f2.isDirectory()) == true) {
return -1;
} else if ((f2.isDirectory() && !f1.isDirectory()) == true) {
return 1;
} else {
return f1.getName().compareToIgnoreCase(f2.getName());// 最后比较文件
}
}
}
}
};
posted on 2012-05-10 11:49  txf2004  阅读(567)  评论(0编辑  收藏  举报