Getting file creation date / time

This seems like a pretty simple question, but I could not find the final answer anywhere on the Internet. How can I get the date / time when the file was created through the Java file manager? Besides just the file name, what else can I get about file properties?

+6
java date file properties
source share
1 answer

I'm not sure how you will get it using Java 6 and below. With the API APIs of the new version of Java 7, it will look like this:

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

As CoolBeans said, not all file systems save creation time. BasicFileAttributes Javadoc states:

If the file system implementation does not support a timestamp indicating the time the file was created, this method returns the default value for the particular implementation, usually the last modified time or FileTime representing an era (1970-01-01T00: 00: 00Z).

+9
source share

All Articles