How to get file last modified date in java

 Posted On  | Yashwant Chavan 

In this section , you are going to learn how to get the file last modification date and time using java io API

file.lastModified() method return the long value which denotes the time when the file was last modified. Here we are converting that long value into date and converting it into proper date and time format.Refer the below example.

package com.technicalkeeda.app;

import java.io.File;
import java.text.SimpleDateFormat;

public class LastModifiedDateExample {
    public static void main(String[] args) {
      
        File file = new File("c:\\test\\myfile.txt");
      
        SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss");
      
        System.out.println("Modified Date :- " + sdf.format(file.lastModified()));
    }
}

Note:Program output is vary base on your input file last modification date.

Output

Modified Date :- 06-05-2012 15:05:11


© technicalkeeda.com 2017

 |  Find us on Google+ |  Rss Feed

Loaded in 0.0329 seconds.