我需要使用 java 获取 Linux 机器中的文件创建日期。许多解决方法在 Windows 中运行良好,但在 Linux 中失败。需要一种方法来获取 Linux 中的文件创建时间。请注意,我的 linux 机器安装了 java6。任何帮助深表感谢。提前致谢。
最佳答案
您可以使用stat
Linux 中的命令可获取各种日期,但创建日期不可用。
相反,您可以获得有关文件的这 3 个日期:
- 上次访问时间
- 上次修改时间(文件内容)
- 上次更改时间(文件元数据)
编辑:
要获取 Java 中文件的创建/修改时间(如果使用 JDK 1.7),请参阅:http://docs.oracle.com/javase/tutorial/essential/io/fileAttr.html
根据本文档:
A word about time stamps: The set of basic attributes includes three time stamps: creationTime, lastModifiedTime, and lastAccessTime. Any of these time stamps might not be supported in a particular implementation, in which case the corresponding accessor method returns an implementation-specific value.
不幸的是,Linux/Unix 不存储文件的创建时间,因此您无法获取它。
PS:如果您可以使用ext4文件系统
那么您可以在Unix/Linux中获取文件的创建时间。
关于java - 如何使用java在linux中查找文件创建日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18529649/