Change last-modified time

ReturnMethodSummary
booleansetLastModified(long time)Sets the last-modified time of the file or directory named by this abstract pathname.

import java.io.File;
import java.util.Date;

public class Main {

  public static void main(String[] args) {
    File file = new File("c:/a.htm");
    file.setLastModified(new Date().getTime());

    
  }
}

Change last modified time of a file or directory


import java.io.*;
import java.util.Date;

public class Main {
  public static void main(String[] args) {
    File file = new File("C:/data.dat");
    Date lastModified = new Date(file.lastModified());
    System.out.println("Last modified time: " + lastModified);
    lastModified = new Date();
    boolean success = file.setLastModified(lastModified.getTime());
    System.out.println(new Date(file.lastModified()));
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.