How to get Last Modified DateTime of File in Java

Using the below source, you can get the last modified date time of a file in Java.

Full Source Code:

package com.tutorial;

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

public class GettingFileLastModifiedDate 
{
	public static void main(String args[]) 
	{
		File file = new File("E:/invoice5.pdf");
		Date date=null;
		SimpleDateFormat df=null;
		if (!file.isDirectory()) 
		{
			date = new Date(file.lastModified());
			df = new SimpleDateFormat("dd-MMM-yyyy hh:mm:ss ");
			System.out.println("Last Modified DateTime:"+df.format(date).toString());
		} 
		else 
		{
			System.out.println("Sorry, it is a Directory!!!!");
			date = new Date(file.lastModified());
			df = new SimpleDateFormat("dd-MMM-yyyy hh:mm:ss ");
			System.out.println("Last Modified DateTime:"+df.format(date).toString());
		}

	}
}

Output:

Last Modified DateTime:08-Mar-2013 10:18:29