![]() |
The Java Developers Almanac 1.4 |
|
e26. Getting and Setting the Modification Time of a File or DirectoryThis example gets the last modified time of a file or directory and then sets it to the current time. File file = new File("filename");
// 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) {
// operation failed.
}
e20. Creating a File e21. Getting the Size of a File e22. Deleting a File e23. Creating a Temporary File e24. Renaming a File or Directory e25. Moving a File or Directory to Another Directory e27. Forcing Updates to a File to the Disk
© 2002 Addison-Wesley. |