多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
## [文件系统](https://lingcoder.gitee.io/onjava8/#/book/17-Files?id=%e6%96%87%e4%bb%b6%e7%b3%bb%e7%bb%9f) 为了完整起见,我们需要一种方法查找文件系统相关的其他信息。在这里,我们使用静态的**FileSystems**工具类获取"默认"的文件系统,但你同样也可以在**Path**对象上调用**getFileSystem()**以获取创建该**Path**的文件系统。你可以获得给定*URI*的文件系统,还可以构建新的文件系统(对于支持它的操作系统)。 ~~~ // files/FileSystemDemo.java import java.nio.file.*; public class FileSystemDemo { static void show(String id, Object o) { System.out.println(id + ": " + o); } public static void main(String[] args) { System.out.println(System.getProperty("os.name")); FileSystem fsys = FileSystems.getDefault(); for(FileStore fs : fsys.getFileStores()) show("File Store", fs); for(Path rd : fsys.getRootDirectories()) show("Root Directory", rd); show("Separator", fsys.getSeparator()); show("UserPrincipalLookupService", fsys.getUserPrincipalLookupService()); show("isOpen", fsys.isOpen()); show("isReadOnly", fsys.isReadOnly()); show("FileSystemProvider", fsys.provider()); show("File Attribute Views", fsys.supportedFileAttributeViews()); } } /* 输出: Windows 10 File Store: SSD (C:) Root Directory: C:\ Root Directory: D:\ Separator: \ UserPrincipalLookupService: sun.nio.fs.WindowsFileSystem$LookupService$1@15db9742 isOpen: true isReadOnly: false FileSystemProvider: sun.nio.fs.WindowsFileSystemProvider@6d06d69c File Attribute Views: [owner, dos, acl, basic, user] */ ~~~ 一个**FileSystem**对象也能生成**WatchService**和**PathMatcher**对象,将会在接下来两章中详细讲解。