Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Example of getLastModifiedTime() method in java.nio.*.

Tags:

java

In Java 1.7, I'd read there are direct method to get last modified time of a file but I cant figure out what values should i pass to the parameters of LinkOptions. I'd appreciate the Most Simple Example. Thank You!

like image 216
Raj Avatar asked Jan 16 '23 10:01

Raj


2 Answers

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

Java Doc BasicFileAttributes#lastModifiedTime

like image 88
Amit Deshpande Avatar answered Jan 18 '23 00:01

Amit Deshpande


Or directly:

File file = new File(...);
FileTime time = Files.getLastModifiedTime(file.toPath());
like image 28
Philippe Franklin Avatar answered Jan 17 '23 22:01

Philippe Franklin