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.
    }
  }
}




















Home »
  Java Tutorial »
    I/O »




Binary File
Byte Array
CharSet
Checksum
Console
Create Copy Move Delete
Directory
Drive
Encode Decode
File Attribute
File Lock
File System
GZIP
Jar File
NIO Buffer
Path
Scanner
StreamTokenizer
Temporary File
Text File
Zip