java - 如何在 linux/unix 文件系统的 java 中确定文件创建时间戳

标签 java linux file

我尝试使用下面的代码来获取 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/

相关文章:

Java JTable 更新行

java - 从 SurfaceView 内部启动 Activity

ruby读取csv,但同时读取两个不同的行

Python:打开(文件名, 'w')用于不存在的文件

java - 应用程序的大小,如何确定

java - matcher.group() 的内存分配

linux - 如何编写一个 shell 脚本来一次将多行数据追加到 3 个不同的文件中,并搜索该数据是否已存在并忽略它?

linux - 服务器之间的 SSH 登录仍然要求输入密码,为什么?

Linux stdout stderr 重定向到文件 : different from terminal output

java - 如何选择 "My Documents"文件保存路径