Get the Last Access Time for a File

后端 未结 2 2029
长情又很酷
长情又很酷 2020-12-01 16:39

I know that using File object we can get the last modified time for a File (i.e. File.lastModified()). But, my requirement is to get the last a

2条回答
  •  时光取名叫无心
    2020-12-01 17:26

    You will need to use the new file I/O API (NIO2) which comes with Java 7. It has a method lastAccessTime() for reading the last access time.

    Here is a usage example:

    Path file = ...
    BasicFileAttributes attrs = Files.readAttributes(file, BasicFileAttributes.class);
    FileTime time = attrs.lastAccessTime();
    

    For more information see Managing Metadata in the Java Tutorial.

提交回复
热议问题