1import java.io.*;
2import java.util.Date;
3import java.text.SimpleDateFormat;
4public class LastModifiedDateDemo
5{
6 public static void main(String[] args)
7 {
8 File file = new File("d:\\modifiedFile.txt");
9 System.out.println("Before - file last modified date: " + file.lastModified());
10 SimpleDateFormat sim = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
11 System.out.println("After - file last modified date: " + sim.format(file.lastModified()));
12 }
13}
1Path file = ...;
2BasicFileAttributes attr = Files.readAttributes(file, BasicFileAttributes.class);
3
4System.out.println("creationTime: " + attr.creationTime());
5System.out.println("lastAccessTime: " + attr.lastAccessTime());
6System.out.println("lastModifiedTime: " + attr.lastModifiedTime());