Home > Java > javaTutorial > Java Example - Modify the last modification date of a file

Java Example - Modify the last modification date of a file

黄舟
Release: 2017-02-15 10:12:59
Original
1515 people have browsed it

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());
   }}
Copy after login

The output of the above code is:

Sat Mar 21 22:00:48 CST 2015
true
Fri Apr 10 11:09:19 CST 2015
Copy after login

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)!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template