get file last modified time in java program

The lastModified() method of File class is used to get file last modified time in java.

Example:

package com.w3spoint;
 
import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
 
public class FileLastModifiedTest {
  public static void main(String args[]){
	  File file = new File("TestProp.properties");
	  Date date = new Date(file.lastModified());
	  DateFormat formatter = new SimpleDateFormat("HH:mm:ss");
	  String dateFormatted = formatter.format(date);
      System.out.println(dateFormatted);
  }
}

Output:

TestProp.xml

16:14:50

Download this example.

Please follow and like us:
Content Protection by DMCA.com