How to discover a File’s creation time with Java?

With the release of Java 7 there is a built-in way to do this:

Path path = Paths.get("path/to/file");
BasicFileAttributes attributes = Files.readAttributes(path, BasicFileAttributes.class);
FileTime creationTime = attributes.creationTime();

It is important to note that not all operating systems provide this information. I believe in those instances this returns the mtime which is the last modified time.

Windows does provide creation time.

Leave a Comment