Java IO Tutorial - Java File.setLastModified(long time)


File.setLastModified(long time) has the following syntax.

public boolean setLastModified(long time)


In the following code shows how to use File.setLastModified(long time) method.

/*  w  ww  .  j a  va  2  s  . c o m*/

import java.util.Date;

public class Main {
  public static void main(String[] args) {
    File f = new File("C:/test.txt");
    long millisec = new Date().getTime();

    // set last modified time
    boolean bool = f.setLastModified(millisec);

    System.out.println("lastModified() succeeded?: " + bool);


The code above generates the following result.