Possible Duplicate:
Getting the last access time for a file in Java
I'm using JDK 1.6 and tried various times for getting the Date and time of last access of a file.
But could not find exact solution.
Possible Duplicate:
Getting the last access time for a file in Java
I'm using JDK 1.6 and tried various times for getting the Date and time of last access of a file.
But could not find exact solution.
java.io.File#lastModified()
returns the date when the file is last modified as a long, i.e number of milliseconds since jan 1 1970. You can set that in a java.util.Date
or java.util.Calendar
to get human readable date.
In 1.6 as people have said you can get the last modified date. Not hte last accessed date though.
If you can access to java 7 then there is the BasicFileAttibutes interface that would give you this information. For example
Path file = ...
BasicFileAttributes attrs = Files.readAttributes(file, BasicFileAttributes.class);
attrs.lastAccessTime();