The following table lists the valid attribute names that can be used with getAttribute()
method:
Attribute Name | Data Type |
---|---|
lastModifiedTime | FileTime |
lastAccessTime | FileTime |
creationTime | FileTime |
size | long |
isRegularFile | Boolean |
isDirectory | Boolean |
isSymbolicLink | Boolean |
isOther | Boolean |
fileKey | Object |
import java.io.IOException; import java.nio.file.Files; 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("Main.java"); FileTime fileTime = FileTime.fromMillis(1000L * 60 * 60 * 24 * 1000); try {/*from w w w .ja v a 2 s.c o m*/ Files.setAttribute(path, "basic:lastAccessTime", fileTime); System.out.println(fileTime); } catch (IOException e) { e.printStackTrace(); } } }