In late 1995, the Java programming language burst onto the Internet scene and gained instant celebrity status.
Saturday, February 26, 2011
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();
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment