How to check the Date and time of Access (last modified) of a File using Java?

You can get the last modified date of a file using the lastModified() method of the File class.


Live Demo

import java.util.Date;

public class FindingDirectories {
   public static void main(String args[]) {
      String dir ="C:/movies";
      File directory = new File(dir);
      File[] fileList = directory.listFiles();

      for (File file : fileList) {
         Date date = new Date(file.lastModified());


Arundhati HD.mp4
Fri Dec 01 17:16:22 IST 2017
Okka Ammai Tappa.mkv
Fri Nov 17 14:29:35 IST 2017
Padamati Sandhya Ragam.mp4
Wed Dec 06 09:53:07 IST 2017
Lakshmi Srinivas
Lakshmi Srinivas

Programmer / Analyst / Technician