Java File Last Modified

Hi guys!!! Welcome to flower brackets blog. In this post you will learn java file last modified.

java file last modified

To determine how to get the file last modified date in java we will be using Java.io.File.lastModified() method. This method return time in milliseconds. You can format it to human readable format using SimpleDateFormat.

Let’s see java file lastModified() method example,

Read Also – Date Time Java Program

Example:

import java.io.*;
import java.util.Date;
import java.text.SimpleDateFormat;

public class LastModifiedDateTime
{
   public static void main(String[] args)
   {
      File file = new File("C:\\modifiedFile.txt");
      System.out.println("Before file format : " + file.lastModified());
      SimpleDateFormat sim = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
      System.out.println("After file format : " + sim.format(file.lastModified()));
   }
}

Output:

Before file format : 1486480590836
After file format : 02/07/2014 05:14:10


Conclusion

That’s it guys. This is all about how to get the last modified date of a file in java. I hope you have understood the concept.

You can subscribe to my blog flower brackets if you haven’t already.

Do share this post if you like.

Related Posts