Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I have directory of files that are named, for example, page1.txt, page2.txt,...I have a lot of them (more than 1000).
When I use
File f = new File("path_to_directory");
String[] list = f.list();I get a list of files but they are out of order. Instead of being page1.txt, page2.txt...it comes out as page1.txt, page10.txt, page100.txt, etc.
Basically, how can I sort the array so that it is in the correct order?
A few things to note:
1. the naming scheme will no always be page + number + .txt but there will always be a pattern somewhere in the file name
2. OSX, Windows, and Linux all are able to show the files in the correct order in the GUI but not when you do it in the terminal (cd path_to_directory then ls).Thanks for the help, and ask questions if you need clarification on something.
-Matt

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |