Get and Set the Modification Time of a File or Directory in Java
Description
The following code shows how to get and Set the Modification Time of a File or Directory.
Example
/*from w w w .java 2 s .co m*/
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.
}
}
}