2010-05-12 84 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()),並通過檢查名稱來確定哪些文件夾位於所需文件夾內。

相關問題