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

相关文章

最近看了一下学习资料,感觉进制转换其实还是挺有意思的,尤...
/*HashSet 基本操作 * --set:元素是无序的,存入和取出顺序不...
/*list 基本操作 * * List a=new List(); * 增 * a.add(inde...
/* * 内部类 * */ 1 class OutClass{ 2 //定义外部类的成员变...
集合的操作Iterator、Collection、Set和HashSet关系Iterator...
接口中常量的修饰关键字:public,static,final(常量)函数...