微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

java – 获取文件创建的日期/时间

这似乎是一个非常直截了当的问题,但我无法在网上找到明确的答案.如何通过 Java文件管理器获取文件的创建日期/时间?除了文件名称,我还能得到关于文件的“属性”的其他内容吗?

解决方法

我不确定你是如何使用Java 6及以下版本的.使用Java 7的新文件系统API,它看起来像这样:
Path path = ... // the path to the file
BasicFileAttributes attributes = 
    Files.readAttributes(path,BasicFileAttributes.class);
FileTime creationTime = attributes.creationTime();

正如CoolBeans所说,并非所有文件系统都存储创建时间. BasicFileAttributes Javadoc声明:

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).

原文地址:https://www.jb51.cc/java/121809.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐