Tutorialspoint examples

Learn java tutorial with examples for beginners online

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.tutorialspointexamples;
 
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.

Download tutorialspointexamples Android App
Copyright © 2018 Tutorialspoint examples DMCA.com Protection Status