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.

Also read – date time java program

Let’s see how to get the file last modified date in java,

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

public class LastModifiedDateDemo
{
   public static void main(String[] args)
   {
      File file = new File("d:\\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

Related Posts