3:11 pm - Tuesday November 23, 6528

To find last modified files using lastModified()

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

 

This tutorial explains how To find last modified files using lastModified(),Use the SimpleDateFormat(“MM/dd/yyyy”) constructor to make a newSimpleDateFormat class instance.

 

import java.io.File;

import java.text.SimpleDateFormat;

import java.util.Date;

public class FileLastModified

{

	public static void main(String[] args)

	{

		File f = new File("/home/mathan/Documents/abcd.txt");

		long datetime = f.lastModified();

		Date d = new Date(datetime);

		SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss");

		String dateString = sdf.format(d);

		System.out.println("The file was last modified on: " + dateString);

	}

}

Output

  The file was last modified on: 01-01-1970 12:00:00

BACK

Filed in: Java Examples

Comments are closed.