Get or set the modification time of a file or directory

From CodeCodex



    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.


fname = "file_name"
# Get the last access time and the last modified time
puts atime = File.atime(fname)          # last access time
puts mtime = File.mtime(fname)          # modification time

# Set the last modified time
mtime =
File.utime(atime, mtime, fname)