使用File类的fileToChange.lastModified()和fileToChangesetLastModified()方法来修改文件最后的创建日期
完整代码
import java.io.File;
import java.util.Date;public class Main {public static void main(String[] args) throws Exception {File fileToChange = new File("C:/test.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());}
}
结果输出
Sat Mar 21 22:00:48 CST 2018
true
Fri Apr 10 11:09:19 CST 2018