集册 Java实例教程 还可以使用file s.setLastModifiedTime()方法更新文件的上次修改时间:

还可以使用file s.setLastModifiedTime()方法更新文件的上次修改时间:

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

444
还可以使用Files.setLastModifiedTime()方法来完成文件的上次修改时间:

import java.io.IOException;

import java.nio.file.Files;

import java.nio.file.Path;

import java.nio.file.Paths;
/** from 
NowJava.com**/

import java.nio.file.attribute.FileTime;


public class Main {

  public static void main(String[] args) {


    Path path = Paths

        .get(

            "D:\\folder0\\Java\\JDK7\\folder5\\code\\folder1\\folder2\\folder6",

            "test.txt");


    // update any or all of the file's last modified time, last access time, and

    // create time attributes

    long time = System.currentTimeMillis();

    FileTime fileTime = FileTime.fromMillis(time);

    // update the file's last modified time with the setLastModifiedTime method/*来自 N o w J a v 
展开阅读全文