programming-examples/java/Core_Java/Getting and Setting the Modification Time of a Fil.java
2019-11-15 12:59:38 +01:00

22 lines
688 B
Java

Getting and Setting the Modification Time of a File or Directory
public static void main(String args[]){
try{
File file = new File("file.txt");
// Get the last modified time
long modifiedTime = file.lastModified();
// 0L is returned if the file does not exist
// Set the last modified time
long newModifiedTime = System.currentTimeMillis();
boolean success = file.setLastModified(newModifiedTime);
if (!success) {
System.out.println("Operation failed");
}
}
catch (Exception ioe){
ioe.printStackTrace();
}
}