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开发者_StackOverflow中文版 zipped folder?
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 the ZipEntry.getName()
and see if it 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);
}
}
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.
Can you just use entries()
? API link
精彩评论