Wednesday, July 1, 2009

Sorting list of FIles in Java (returned from listFiles)

Here is some handy code to get files in order...

File[] files = dir.listFiles();
Arrays.sort(files, new Comparator() {
public int compare(File f1, File f2) {
return f1.getName().compareTo(f2.getName());
}
});

No comments: