我正致力于创建一个基于 link 的自定义文件系统.我创建了一个 CustomFileSystemProvider
(和其他 CustomFileSystem 类)并覆盖了所需的方法。 CustomFileSystemProvider
的 getScheme()
方法返回字符串“myfs”。
但是,当我尝试使用以下代码测试此文件系统时
FileSystem fs = FileSystems.newFileSystem(URI.create("myfs://a_remote_resource"), env);
我得到一个错误
java.nio.file.ProviderNotFoundException: Provider "myfs" not found
at java.nio.file.FileSystems.newFileSystem(FileSystems.java:341)
at java.nio.file.FileSystems.newFileSystem(FileSystems.java:276)
at Tester.main(Tester.java:30)
我在 FileSystemProvider.installedProviders()
返回的列表中没有看到我的自定义文件系统。我不确定将自定义 FS 注册为“installedProvider”需要什么。
最佳答案
A FileSystemProvider
已按照 FileSystems 的 Javadoc 中的说明加载。 :
Installed providers are loaded using the service-provider loading facility defined by the ServiceLoader class. Installed providers are loaded using the system class loader. If the system class loader cannot be found then the extension class loader is used; if there is no extension class loader then the bootstrap class loader is used. Providers are typically installed by placing them in a JAR file on the application class path or in the extension directory, the JAR file contains a provider-configuration file named java.nio.file.spi.FileSystemProvider in the resource directory META-INF/services, and the file lists one or more fully-qualified names of concrete subclass of FileSystemProvider that have a zero argument constructor
关于java - 实例化自定义 java (nio) 文件系统的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34477609/