Example usage for java.nio.file Files setAttribute

List of usage examples for java.nio.file Files setAttribute

Introduction

In this page you can find the example usage for java.nio.file Files setAttribute.

Prototype

public static Path setAttribute(Path path, String attribute, Object value, LinkOption... options)
        throws IOException 

Source Link

Document

Sets the value of a file attribute.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {

    Path path = Paths.get("C:/tutorial/Java/JavaFX", "Topic.txt");
    long time = System.currentTimeMillis();
    FileTime fileTime = FileTime.fromMillis(time);
    try {/*from  w w  w  . ja v  a 2s  .  c om*/
        Files.setAttribute(path, "basic:lastModifiedTime", fileTime, LinkOption.NOFOLLOW_LINKS);
        Files.setAttribute(path, "basic:creationTime", fileTime, LinkOption.NOFOLLOW_LINKS);
        Files.setAttribute(path, "basic:lastAccessTime", fileTime, LinkOption.NOFOLLOW_LINKS);
    } catch (IOException e) {
        System.err.println(e);
    }

}