1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
/* Get Last modification time of a file or directory This Java example shows how to determine last modification time of a particular file or directory using lastModified method of Java File class. */ import java.io.*; import java.util.Date; public class GetLastModificationTimeOfAFile { public static void main(String[] args) { //create file object File file = new File("C://FileIO//demo.txt"); /* * To determine last modification time of a particular file or directory, use * long lastModified() method of Java File class. * * This method returns long representing the time file was last modified as * milliseconds since Jan 01, 1970 00:00:00. This * method returns 0L if the file does not exists or in case of IOException. * */ long lastModified = file.lastModified(); System.out.println("File was last modifed at : " + new Date(lastModified)); } } /* Typical output would be File was last modifed at : Sun Jan 06 18:24:01 EST 2008 */ |
Add Comment