How to get file last modified date in java

How to get file last modified date in java

By Yashwant Chavan, Views 3894, Date 05-Jun-2012

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

tags java

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.


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.


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


Hi there! I am founder of and programming enthusiast. My skills includes Java,J2EE, Spring Framework, Nodejs, PHP and lot more. If you have any idea that you would want me to develop? Lets connect: yashwantchavan[at][]