2010-05-12 90 views
3
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? 

回答

5

看起来好像有一种方法可以在特定目录下枚举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); 
    } 
} 
1

你不 - 至少不是直接。 ZIP文件实际上并不分层次。枚举所有条目(通过ZipFile.entries()或ZipInputStream.getNextEntry()),并通过检查名称来确定哪些文件夹位于所需文件夹内。

相关问题