I'm writing a code where in there a bunch of files that have to be taken as input from a directory.
The program works fine, but the problem comes up in the way the files are picked. In my directory when I do a sort the first file shown is file5521.3, but in my program the first file that is picked up is file5521.100. THis is pretty confusing.
I've also tried using Arrays.sort(list, NameFileComparator.NAME_COMPARATOR), but it also gives the same result as previous.
Below is my code.
please let me know how can I do this.
Working Solution with Last Modified Date
The Comparator works fine with last modified date, but when I try it with below code. The result is same as previous.
In my Windows Explorer It looks like the Windows Image.
But file5523.100 is always before file5523.3.
If you want the files to be sorted by the numeric value of the extension rather than by their names, you will have to write a Comparator for the two parts of the file nam.
Campbell Ritchie wrote:But file5523.100 is always before file5523.3.
If you want the files to be sorted by the numeric value of the extension rather than by their names, you will have to write a Comparator for the two parts of the file nam.
You mean that I've to consider filename after the period?