Java Examples - File Modification Date

Advertisements


Problem Description:

How to get last modification date of a file ?

Solution:

This example shows how to get the last modification date of a file using file.lastModified() method of File class.

import java.io.File;
import java.util.Date;

public class Main {
   public static void main(String[] args) {
      File file = new File("Main.java");
      Long lastModified = file.lastModified();
      Date date = new Date(lastModified);
      System.out.println(date);
   }
}

Result:

The above code sample will produce the following result.

Tue 12 May 10:18:50 PDF 2009


Advertisements
Advertisements