CodesJava

Easy learning with example program codes

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.codesjava;
 
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:
error
Posted in IO   








Copyright © 2019 CodesJava DMCA.com Protection Status