private static final Comparator<File> FILE_COMPARATOR = new Comparator<File>() {
@Override
public int compare(File lhs, File rhs) {
boolean ldir = lhs.isDirectory();
boolean rdir = rhs.isDirectory();
if (ldir == rdir) {
// both are files or directories
return lhs.getName().compareToIgnoreCase(rhs.getName());
} else if (ldir) {
return -1;
} else {
return 1;
}
}
};