集册 Java实例教程 设置文件或目录的上次修改时间

设置文件或目录的上次修改时间

欢马劈雪     最近更新时间:2020-01-02 10:19:05

525
设置文件或目录的上次修改时间

import java.io.*;

import java.util.Date;

 

public class Main {/*来自 时代Java公众号*/

 

  public static void main(String[] args) {

   

    File file = new File("C://Folder//ReadText.txt");

   

    Date lastModified = new Date(file.lastModified());

    System.out.println("Last modified time of file is : " + lastModified );

   

    lastModified = new Date();

   

    boolean blnSuccess = file.setLastModified(lastModified.getTime());

   

    System.out.println("Was last modified time set successfully ?:" + blnSuccess);

   

    System.out.
展开阅读全文