java - 实例化自定义 java (nio) 文件系统的问题

标签 java nio

我正致力于创建一个基于 link 的自定义文件系统.我创建了一个 CustomFileSystemProvider(和其他 CustomFileSystem 类)并覆盖了所需的方法。 CustomFileSystemProvidergetScheme() 方法返回字符串“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/

相关文章:

JSONObject 的 Java NoClassDefFoundError 异常

java - @RequestParam 为空(Spring MVC)

java - 向多个客户端广播对象

java - Java中的异步文件NIO有什么好处?

java - 如何重构这段IO代码?

java - Java 中的可迭代 gzip 放气/膨胀

java - Hibernate使用deleted属性处理已删除的对象

使用 SocketChannel 的 Java HTTP 客户端,以便我可以中断读取请求的线程

nio - 使用Java 7新IO获取文件/目录大小

java - Hibernate PropertyAccessException : IllegalArgumentException occurred calling getter? 发生了什么?