I have a folder in windows/Linux which has below files
test_1a.play
test_1AA.play
test_1aaa.play
test-_1AAAA.play
I am reading files and and storing it But windows and linux gives different order. As my application runs in both platform I need consistent order(Linux order). Any suggestion for fixing this.
File root = new File( path );
File[] list = root.listFiles();
list<File> listofFiles = new ArrayList<File>();
.....
for ( File f : list ) {
...
read and store file in listofFiles
...
}
Collections.sort(listofFiles);
Windows gives me below order
test-_1AAAA.play
test_1a.play
test_1AA.play
test_1aaa.play
Linux gives me below order
test-_1AAAA.play
test_1AA.play
test_1a.play
test_1aaa.play
You will need to implement your own
Comparator<File>since theFile.compareTouses the “systems” order.I think (not checked) that Linux uses the “standard” order by file name (case sensitive) so an example implementation could look like this:
Outputs: