在Java中确定文件创建日期 [英] Determine file creation date in Java

查看:105
本文介绍了在Java中确定文件创建日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在StackOverflow上还有另一个类似的问题:(一个href =http://stackoverflow.com/questions/741466/how-to-get-creation-date-of-a-file-in-java >如何获取Java中的文件的创建日期),但是答案并不是真的,因为OP具有可以通过其他机制解决的不同需求。我正在尝试创建一个可以按年龄排序的目录中的文件列表,因此需要创建文件。

There is another similar question to mine on StackOverflow (How to get creation date of a file in Java), but the answer isn't really there as the OP had a different need that could be solved via other mechanisms. I am trying to create a list of the files in a directory that can be sorted by age, hence the need for the file creation date.

我没有找到任何在网路拖网捕鱼之后,很好的做法。是否有获取文件创建日期的机制?

I haven't located any good way to do this after much trawling of the web. Is there a mechanism for getting file creation dates?

目前在Windows系统上的BTW可能还需要在Linux系统上工作。另外,我不能保证在名称中嵌入创建日期/时间的文件命名约定。

BTW, currently on a Windows system, may need this to work on a Linux system as well. Also, I can't guarantee that a file naming convention would be followed where the creation date/time is embedded in the name.

推荐答案

Java nio 具有访问creationTime和其他元数据的选项,只要文件系统提供它即可。
检查此链接

Java nio has options to access creationTime and other meta-data as long as the filesystem provides it. Check this link out

例如(基于@ ydaetskcoR的评论提供):

For example(Provided based on @ydaetskcoR's comment):

Path file = ...;
BasicFileAttributes attr = Files.readAttributes(file, BasicFileAttributes.class);

System.out.println("creationTime: " + attr.creationTime());
System.out.println("lastAccessTime: " + attr.lastAccessTime());
System.out.println("lastModifiedTime: " + attr.lastModifiedTime());

这篇关于在Java中确定文件创建日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆