描述
Get Bulk Attributes with readAttributes()
例子
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.BasicFileAttributes;
public class Main {
public static void main(String[] args) {
BasicFileAttributes attr = null;
Path path = Paths.get("D:\\folder0\\Java\\JDK7\\folder5\\code\\folder1\\folder2\\folder6", "test.txt");
//extract attributes as bulk with readAttributes
try {/* ww w . 21 doc . n e t*/
attr = Files.readAttributes(path, BasicFileAttributes.class);
} catch (IOException e) {
System.err.println(e);
}
System.out.println("File size: " + attr.size());
System.out.println("File creation time: " + attr.creationTime());
System.out.println("File was last time accessed at: " + attr.lastAccessTime());
System.out.println("File was last time modified at: " + attr.lastModifiedTime());
System.out.println("Is directory ? " + attr.isDirectory());
System.out.println("Is regular file ? " + attr.isRegularFile());
System.out.println("Is symbolic link ? " + attr.isSymbolicLink());
System.out.println("Is other ? " + attr.isOther());
}
}