我尝试使用下面的代码来获取 linux 系统中文件的文件创建时间。但不是给出创建时间,而是给出最后修改时间。 请帮助我在 java 中为 linux 文件系统获取文件创建时间。
File f=new File("/var/fileName.csv");
Path p = f.toPath();
BasicFileAttributes attr = Files.readAttributes(p, BasicFileAttributes.class);
System.out.println("creationTime: " + attr.creationTime().toInstant().atZone(ZoneId.systemDefault()));
提前致谢!
最佳答案
阅读Javadoc显示以下内容:
FileTime creationTime()
Returns the creation time. The creation time is the time that the file was created.
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).
所以看起来这是您所在的文件系统以及相应的文件系统实现的问题。
关于java - 如何在 linux/unix 文件系统的 java 中确定文件创建时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53410980/