gpt4 book ai didi

java - 如何在 Java 中枚举压缩文件夹的内容?

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:57:37 24 4
gpt4 key购买 nike

ZipeFile file = new ZipFile(filename);
ZipEntry folder = this.file.getEntry("some/path/in/zip/");
if (folder == null || !folder.isDirectory())
throw new Exception();

// now, how do I enumerate the contents of the zipped folder?

最佳答案

好像没有办法枚举某个目录下的ZipEntry

您必须遍历所有 ZipFile.entries()并根据 ZipEntry.getName() 筛选您想要的那些看看是不是String.startsWith(String prefix) .

String specificPath = "some/path/in/zip/";

ZipFile zipFile = new ZipFile(file);
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry ze = entries.nextElement();
if (ze.getName().startsWith(specificPath)) {
System.out.println(ze);
}
}

关于java - 如何在 Java 中枚举压缩文件夹的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2819427/

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