Search code examples
javafiledirectoryjava-6

How to sort files by creation date using java 1.6


I have a folder with files in there, I have to sort those files by their creation date.

So I want to sort from the oldest to the newest file by creation date.

I saw many answers working with java nio but since I am working with java 1.6 I can not use java nio.

I need help, is there any solution?


Solution

  • If you can use a third party library try JavaXT Core. Should work with Java 1.5 and up.

        javaxt.io.File file = new javaxt.io.File("C:\\Users\\xyz\\Desktop\\myFile.txt");
        System.out.println("Created: " + file.getCreationTime());
        System.out.println("Accessed: " + file.getLastAccessTime());
        System.out.println("Modified: " + file.getLastModifiedTime());