jar 中文件的 AsynchronousFileChannel

AsynchronousFileChannel for a file in a jar

有没有办法为存储在类路径上的 jar 中的文件打开 AsynchronousFileChannel

如果我尝试直接创建 Path,我会得到 FileSystemNotFoundException。 如果我先创建文件系统:

URI uri = ...; //get the URI of a file in a jar
String[] array = uri.toString().split("!");
FileSystem fs = FileSystems.newFileSystem(URI.create(array[0]), Collections.emptyMap());
Path path = fs.getPath(array[1]);
AsynchronousFileChannel ch = AsynchronousFileChannel.open(path);

爆炸UnsupportedOperationException :(

有什么办法可以实现吗?

我的项目是 Spring(为此使用 ClassPathResource),因此 Spring 特定解决方案有效。

JDK 中的 zip 文件系统提供程序不支持异步 I/O 所以这就是抛出 UOE 的原因。