集册 Java实例教程 更新基本属性

更新基本属性

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

433
基本属性名称在此处列出:
/*
时 代 J a v a 公 众 号 - N o w J a v  a . c o m 提供
*/

import java.io.IOException;

import java.nio.file.Files;

import java.nio.file.LinkOption;

import java.nio.file.Path;

import java.nio.file.Paths;

import java.nio.file.attribute.FileTime;


public class Main {

  public static void main(String[] args) {

    Path path = Paths.get("D:\\folder0\\","test.txt");


    long time = System.currentTimeMillis();

    FileTime fileTime = FileTime.fromMillis(time);

    try {

        Files.setAttribute(path, "basic:lastModifiedTime", fileTime, LinkOption.NOFOLLOW_LINKS);

        Files.setAttribute(path, "basic:creationTime", fileTime, LinkOption.NOFOLLOW_LINKS);

        Files.setAttribute(path, 
展开阅读全文