gpt4 book ai didi

java - jar 中文件的 AsynchronousFileChannel

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:49:35 24 4
gpt4 key购买 nike

有没有办法为存储在类路径上的 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 的原因。

关于java - jar 中文件的 AsynchronousFileChannel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45942456/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com