dcsimg
Getting a list of files from a directory in a sorted order
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Ben_Israel
Posted On:   Tuesday, June 5, 2001 10:52 AM

Is there a method or any option with the list() method using which I can get the file list retrieved from a directory, in a sorted order?

I can do this using the time stamp of files (using long file.lastModified()) and then sorting the list based upon the time stamp - but there could be an easier way to do this at one shot???

Re: Getting a list of files from a directory in a sorted order

Posted By:   Tim_Rohaly  
Posted On:   Wednesday, June 6, 2001 08:53 AM

Sorting is a separate operation, and as such it
is (and should be!) distinct from any of the default
methods such as list(). There are literally
hundreds of ways to sort, and hundreds of keys to
sort on. The Java Collections
classes provide you will all the tools you will need to
sort the returned list of files in any way you feel appropriate.
In particular, check out java.util.Arrays
and the Collections FAQ.
About | Sitemap | Contact