gpt4 book ai didi

java - 在 Java 中,您可以浏览嵌套 zip 文件的内容而不膨胀父文件吗?

转载 作者:太空宇宙 更新时间:2023-11-04 09:56:53 25 4
gpt4 key购买 nike

我有一个 zip 文件,其中包含 zip 文件(它们本身可能包含 zip 文件)。

parent.zip
|- child_1.zip
| |- foo.txt
|
|- child_2.zip
| |- bar.txt
|
|- baz.txt

使用 ZipFile,我可以获取父 zip 文件的 ZipEntries,并查看子文件(child_1.zip、child_2.zip、baz.txt),但我无法找到一种方法来检查这些子 zip 文件(foo.txt、bar.txt)的内容而不膨胀父 zip。

这可能吗,还是我需要膨胀parent.zip?

最佳答案

可以使用zip file system使用 jar:file: 协议(protocol):

            URI uri = new URI(
"jar:file:/home/.../.../external.zip!/.../internal.zip!/");
Map<String, ?> env = new HashMap<>();
try (FileSystem zipfs = FileSystems.newFileSystem(uri, env)) {
Path rootPath2 = zipfs.getPath("/");
Files.walk(rootPath2).forEach(p -> {
System.out.printf("Path %s%n", p.toString());
});
}

对于递归遍历,必须创建带有“!/”的 URI,并自行执行递归。

使用文件可以将文件复制到zip文件系统中。 (这里我有一些疑问。)

关于java - 在 Java 中,您可以浏览嵌套 zip 文件的内容而不膨胀父文件吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54030188/

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