Mega Code Archive

 
Categories / Java / File Input Output
 

Getting and Setting the Modification Time of a File or Directory

import java.io.File; public class Main {   public static void main(String[] argv) throws Exception {     File file = new File("filename");     long modifiedTime = file.lastModified();     // 0L is returned if the file does not exist     long newModifiedTime = System.currentTimeMillis();     boolean success = file.setLastModified(newModifiedTime);     if (!success) {       // operation failed.     }   } }