java.nio.file
包来获取文件的属性:,,``java,import java.nio.file.*;,import java.nio.file.attribute.*;,,public class FileInfo {, public static void main(String[] args) {, Path filePath = Paths.get("/path/to/your/file.txt");, try {, BasicFileAttributes attrs = Files.readAttributes(filePath, BasicFileAttributes.class);, System.out.println("Creation Time: " + attrs.creationTime());, System.out.println("Last Access Time: " + attrs.lastAccessTime());, System.out.println("Last Modified Time: " + attrs.lastModifiedTime());, System.out.println("File Size: " + attrs.size() + " bytes");, } catch (IOException e) {, e.printStackTrace();, }, },},
`,,这段代码会输出指定文件的创建时间、最后访问时间、最后修改时间和文件大小。请将
"/path/to/your/file.txt"` 替换为你要查询的文件路径。Powered By Z-BlogPHP 1.7.3