如何在 Java 中枚举压缩文件夹的内容?
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?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看起来没有办法枚举某个目录下的 ZipEntry 。
您必须遍历所有
ZipFile.entries()
并根据ZipEntry.getName()
并查看是否String.startsWith(字符串前缀)< /代码>
。
It doesn't look like there's a way to enumerate
ZipEntry
under a certain directory.You'd have to go through all
ZipFile.entries()
and filter the ones you want based on theZipEntry.getName()
and see if itString.startsWith(String prefix)
.你不知道——至少,不直接知道。 ZIP 文件实际上没有分层结构。枚举所有条目(通过 ZipFile.entries() 或 ZipInputStream.getNextEntry()),并通过检查名称来确定哪些条目位于所需的文件夹中。
You don't - at least, not directly. ZIP files are not actually hierarchical. Enumerate all the entries (via ZipFile.entries() or ZipInputStream.getNextEntry()) and determine which are within the folder you want by examining the name.
你可以只使用
entries()
吗? API 链接Can you just use
entries()
? API link