Sorting a directory content by last modify date

J

J_Zanetti

Hello everyone,

Im trying to sort the content of a directory (a file list) according
to the lastModified attribute of the object.
I get the array of files in this way:

File file = new File(directoryname);
String listoffile[] = file.list();

I would like that this listoffile[] array contains the files sorted by
its lastModified date...
is there any way to do that?

thanks everyone who can help me :)
 
A

Andrew Thompson

Im trying to sort the content of a directory (a file list) according
to the lastModified attribute of the object. ....
I would like that this listoffile[] array contains the files sorted by
its lastModified date...
is there any way to do that?

Create a suitable java.util.Comparator. Read the
JDocs for same, to see some ways to sort them.

HTH

Andrew T.
 
V

voorth

Im trying to sort the content of a directory (a file list) according
to the lastModified attribute of the object. ...
I would like that this listoffile[] array contains the files sorted by
its lastModified date...
is there any way to do that?Create a suitable java.util.Comparator. Read the
JDocs for same, to see some ways to sort them.
It might also be a good idea to use File.listFiles() instead of
File.list(). Processing a File array instead of a String array will
make your Comparator a lot simpler...

Henk van Voorthuijsen
 
J

J_Zanetti

It might also be a good idea to use File.listFiles() instead of
File.list(). Processing a File array instead of a String array will
make your Comparator a lot simpler...

Thank to both of you that answered...I used comparator with array of
files and it works greatly ;)
Thank so much :)
 
P

Patricia Shanahan

J_Zanetti said:
Hello everyone,

Im trying to sort the content of a directory (a file list) according
to the lastModified attribute of the object.
I get the array of files in this way:

File file = new File(directoryname);
String listoffile[] = file.list();

I would like that this listoffile[] array contains the files sorted by
its lastModified date...
is there any way to do that?

thanks everyone who can help me :)

I think you are making a mistake in using file.list directly. You would
do better to use file.listFiles. You could sort the resulting File[]
according to lastModified() result, and then extract the names in the
right order.

Patricia
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top