开发者

Getting date/time of creation of a file

This seems like a pretty straightforward quest开发者_如何学编程ion but I haven't been able to find a definitive answer anywhere online. How can I get the date/time a file was created through Java's file manager? Aside from just the name of a file, what else can I get about the file's "properties"?


I'm not sure how you'd get it using Java 6 and below. With Java 7's new file system APIs, it'd 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 store the creation time. The BasicFileAttributes Javadoc states:

If the file system implementation does not support a time stamp to indicate the time when the file was created then this method returns an implementation specific default value, typically the last-modified-time or a FileTime representing the epoch (1970-01-01T00:00:00Z).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜