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
Result
The above code will produce the following output.
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
0 comments:
Post a Comment