The following example demonstrates using the fileToChange.lastModified() and fileToChange setLastModified() methods of the File class to modify the last modification date of the file:
/* author by w3cschool.cc Main.java */import java.io.File;import java.util.Date;public class Main { public static void main(String[] args) throws Exception { File fileToChange = new File ("C:/myjavafile.txt"); fileToChange.createNewFile(); Date filetime = new Date (fileToChange.lastModified()); System.out.println(filetime.toString()); System.out.println (fileToChange.setLastModified (System.currentTimeMillis())); filetime = new Date (fileToChange.lastModified()); System.out.println(filetime.toString()); }}
The output of the above code is:
Sat Mar 21 22:00:48 CST 2015 true Fri Apr 10 11:09:19 CST 2015
The above is the Java example - modify the last modification date of the file. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!