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 :)
Andrew Thompson - 29 Jan 2007 11:39 GMT
..
> 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.
voorth - 29 Jan 2007 12:53 GMT
> ..
>
[quoted text clipped - 5 lines]
> > 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_Zanetti - 29 Jan 2007 13:18 GMT
>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 :)
Patricia Shanahan - 29 Jan 2007 14:38 GMT
> Hello everyone,
>
[quoted text clipped - 10 lines]
>
> 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