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.FileSystems; import java.nio.file.Files; import java.nio.file.Path; public class Main { public static void main(String[] args) { try {//from w w w . j a v a 2s .c o m Path path = FileSystems.getDefault().getPath("Main.java"); System.out.println(Files.getAttribute(path, "size")); } catch (IOException ex) { System.out.println("IOException"); } } }