Sort files by name in Java differs from Windows Explorer

Posted by Martyn Hopkins on Stack Overflow See other posts from Stack Overflow or by Martyn Hopkins
Published on 2010-06-18T01:48:51Z Indexed on 2010/06/18 1:53 UTC
Read the original article Hit count: 281

Filed under:

I have a simple Java program which reads a file directory and outputs a file list. I sort the files by name:

String [] files = dirlist.list();

files = sort(files);

My problem is that it sorts by name in a different way than Windows Explorer does.

For instance if I have these files: abc1.doc, abc12.doc, abc2.doc.

Java will sort like this:

abc1.doc abc12.doc abc2.doc

When I open the folder in Explorer, my files are sorted like this:

abc1.doc abc2.doc abc12.doc

How can I make Java sorts my files like in Windows Explorer? Is this a Windows trick?

© Stack Overflow or respective owner

Related posts about java