Monday 14, Apr 2025
We are moved to new domain
Click -> www.ehowtonow.com
Wednesday, 13 May 2015

How to get File Last modified Date in Java

Following example shows how to get file last modified date using file.lastModified() method in Java.

lastModified
public long lastModified() 
Returns the time that the file denoted by this abstract pathname was last modified. Where it is required to distinguish an I/O exception from the case where 0L is returned, or where several attributes of the same file are required at the same time, or where the time of last access or the creation time are required, then the Files.readAttributes method may be used.
Returns:
A long value representing the time the file was last modified, measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970), or 0L if the file does not exist or if an I/O error occurs
Throws:
SecurityException - If a security manager exists and its SecurityManager.checkRead(java.lang.String) method denies read access to the file

Sample Program
FileLastModifiedDate.java
package com.javatutorialcorner.file;

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

public class FileLastModifiedDate {

 public static void main(String[] args) {
  File jtcFile = new File("/home/annamalai/workspace/File/jtc.txt");
  Long lastModified = jtcFile.lastModified();
  Date lastModifiedDate = new Date(lastModified);
  System.out.println("Last Modified Date : " + lastModifiedDate);

 }

}

Result
The above code will produce the following output.

Last Modified Date : Wed May 13 07:48:30 IST 2015

Shop and help us

Flipkart Offer Snapdeal offer Amazon.in offer Amazon.com offer

Related Posts:

  • Create XML File using DOM ParserIn this tutorials we going to see how to create the XML document using DOM parser 1. Create Project Called JavaXML. 2. Create package called com.javatutorialscorner.xml.dom under JavaXML. 3. Create Java class called CreateXML… Read More
  • Java Best Practice – Reuse Objects instead of creating new ones if possibleReuse Objects instead of creating new ones if possibleObject creation is an expensive operation in Java, with impact on both performance and memory utilization.The cost varies depending on the amount of initialization that ne… Read More
  • Read XML File as List of Object using SAX ParserIn this tutorial we are going to see how to read XML file and how to convert it as List of Object using SAX parser 1. Create Project Called JavaXML. 2. Create package called com.javatutorialscorner.xml.sax under JavaXML. 3. … Read More
  • SAX Parser Introduction SAX – Simple API for XML SAX parser work differently with DOM parser.SAX parser is faster and uses less memory than DOM parser.SAX don’t load and XML document into memory and don’t create any object representation of XM… Read More
  • Java XML IntroductionIn Tutorials we are going to see brief introduction about XML and its usage in Java.Java comes with set of API to process XML, we will see all the XML processing API available in JAVA in upcoming chapters.XML OverviewXML – Ex… Read More
  • Blogger Comments
  • Facebook Comments
  • Disqus Comments

0 comments:

Post a Comment

Item Reviewed: How to get File Last modified Date in Java Rating: 5 Reviewed By: eHowToNow