使用BasicFileAttributeView维护基本文件属性
import java.io.IOException;//时代Java公众号 提 供 import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.attribute.BasicFileAttributes; public class Main { public static void main(String[] args) { Path path = FileSystems.getDefault().getPath("/home/docs/users.txt"); try { BasicFileAttributes attributes = Files.readAttributes(path, BasicFileAttributes.class); System.out.println("Creation Time: " + attributes.creationTime()); System.out.println("Last Accessed Time: " + attributes.lastAccessTime()); System.out .println("Last Modified Time: " + attributes.lastModifiedTime()); System.out.println("File Key: " + attributes.fileKey()); System.out.println("Directory: " + attributes.isDirectory()); /* *来 自 时 代 J a v a - N o w J a v a . c o m */ System.out.println("Other Type of File: " + attributes.isOther()); System.out.println("Regular File: " + attributes.isRegularFile()); System.out.println(