Soring a list of files?

D

D. Alvarado

Hello,
Does anyone know a simple way to get a list of a directory's files
returned in alphabetical order? It would be great if I cold work with
the File[] array returned by the java.io.File.listFiles function.
Thanks - Dave
 
C

Christophe Vanfleteren

D. Alvarado said:
Hello,
Does anyone know a simple way to get a list of a directory's files
returned in alphabetical order? It would be great if I cold work with
the File[] array returned by the java.io.File.listFiles function.
Thanks - Dave

Use the java.utils.Arrays.sort(Object[]) method.
 
L

Larry Coon

D. Alvarado said:
Hello,
Does anyone know a simple way to get a list of a directory's files
returned in alphabetical order? It would be great if I cold work with
the File[] array returned by the java.io.File.listFiles function.

Something like this will work:

File files[] = new File("c:\\").listFiles();

Collections.sort(Arrays.asList(files));


There's also a static sort method in class Arrays.
 

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

Members online

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,690
Members
48,796
Latest member
Greg L.

Latest Threads

Top