这似乎是一个非常直截了当的问题,但我无法在网上找到明确的答案.如何通过
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).