I have a set of files in a folder, and all of them starting with a similar name, except one. Here is an example:
Coordinate.txt
Spectrum_1.txt
Spectrum_2.txt
Arrays.sort(fileList, new Comparator()
{
@Override
public int compare(Object f1, Object f2) {
String fileName1 = ((File) f1).getName();
String fileName2 = ((File) f1).getName();
int fileId1 = Integer.parseInt(fileName1.split("_")[1]);
int fileId2 = Integer.parseInt(fileName2.split("_")[1]);
return fileId1 - fileId2;
}
});
make sure to handle files that does not has _ in the name