Java – get the date / time when the file was created

This seems to be a very straightforward question, but I can't find a clear answer on the Internet How to obtain the creation date / time of a file through the java file manager? Besides the name of the file, can I get anything else about the "properties" of the file?

Solution

I'm not sure how you use Java 6 and below Using the new file system API of Java 7, it looks 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 store creation times Basicfileattributes Javadoc declaration:

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>