💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
### [路径分析](https://lingcoder.gitee.io/onjava8/#/book/17-Files?id=%e8%b7%af%e5%be%84%e5%88%86%e6%9e%90) **Files**工具类包含一系列完整的方法用于获得**Path**相关的信息。 ~~~ // files/PathAnalysis.java import java.nio.file.*; import java.io.IOException; public class PathAnalysis { static void say(String id, Object result) { System.out.print(id + ": "); System.out.println(result); } public static void main(String[] args) throws IOException { System.out.println(System.getProperty("os.name")); Path p = Paths.get("PathAnalysis.java").toAbsolutePath(); say("Exists", Files.exists(p)); say("Directory", Files.isDirectory(p)); say("Executable", Files.isExecutable(p)); say("Readable", Files.isReadable(p)); say("RegularFile", Files.isRegularFile(p)); say("Writable", Files.isWritable(p)); say("notExists", Files.notExists(p)); say("Hidden", Files.isHidden(p)); say("size", Files.size(p)); say("FileStore", Files.getFileStore(p)); say("LastModified: ", Files.getLastModifiedTime(p)); say("Owner", Files.getOwner(p)); say("ContentType", Files.probeContentType(p)); say("SymbolicLink", Files.isSymbolicLink(p)); if(Files.isSymbolicLink(p)) say("SymbolicLink", Files.readSymbolicLink(p)); if(FileSystems.getDefault().supportedFileAttributeViews().contains("posix")) say("PosixFilePermissions", Files.getPosixFilePermissions(p)); } } /* 输出: Windows 10 Exists: true Directory: false Executable: true Readable: true RegularFile: true Writable: true notExists: false Hidden: false size: 1631 FileStore: SSD (C:) LastModified: : 2017-05-09T12:07:00.428366Z Owner: MINDVIEWTOSHIBA\Bruce (User) ContentType: null SymbolicLink: false */ ~~~ 在调用最后一个测试方法**getPosixFilePermissions()**之前我们需要确认一下当前文件系统是否支持**Posix**接口,否则会抛出运行时异常。