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
The NameFileComparator class available in Commons IO library that have feature for sorting file array by name,last modified date, size and many more.Files can be sorted in ascending and descending order, with case sensitivity or case insensitivity.
Import :
org.apache.commons.io.comparator.NameFileComparator
Code :
File directory = new File(".");
File[] files = directory.listFiles();
Arrays.sort(files, NameFileComparator.NAME_COMPARATOR)