使用URI scheme可以读取基本上重命名为.zip文件(.ear、.war、.jar等)的存档格式,尽管可能不明智。jar:
例如,以下代码在uri
变量计算为单个顶级存档时运行良好,例如当uri
等于jar:file:///Users/justingarrick/Desktop/test/my_war.war!/
private FileSystem createZipFileSystem(Path path) throws IOException {
URI uri = URI.create("jar:" + path.toUri().toString());
FileSystem fs;
try {
fs = FileSystems.getFileSystem(uri);
} catch (FileSystemNotFoundException e) {
fs = FileSystems.newFileSystem(uri, new HashMap<>());
}
return fs;
}
但是,当 URI 包含嵌套档案时, getFileSystem
andnewFileSystem
调用会失败IllegalArgumentException
,例如当uri
equals jar:jar:file:///Users/justingarrick/Desktop/test/my_war.war!/some_jar.jar!/
(.war内的.jar)时。
嵌套存档文件是否有有效的java.net.URI
方案?