Skip to content

Instantly share code, notes, and snippets.

@onecoders
Created August 14, 2013 07:56
Show Gist options
  • Save onecoders/6228854 to your computer and use it in GitHub Desktop.
Save onecoders/6228854 to your computer and use it in GitHub Desktop.
file sort
private class SortFileName implements Comparator<File> {
@Override
public int compare(File f1, File f2) {
return f1.getName().compareToIgnoreCase(f2.getName());
}
}
private class SortFolder implements Comparator<File> {
@Override
public int compare(File f1, File f2) {
if ((f1.isDirectory() && f2.isDirectory())
|| (!f1.isDirectory() && !f2.isDirectory()))
return 0;
else if (f1.isDirectory() && !f2.isDirectory())
return -1;
else
return 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment