从ZipInputStream复制条目

问题描述 投票:0回答:1

我可以像这样迭代ZipEntryZipInputStream

ByteArrayInputStream schema = new ByteArrayInputStream(schemaData);
ZipInputStream zis = new ZipInputStream(schema);
ZipEntry entry;
while((entry = zis.getNextEntry()) != null) {
     String entryName = entry.getName();
     // filter based on entry name
     // how to copy this entry?
}

如何复制此Zip文件的某些条目?

java stream
1个回答
1
投票

是的,当然有可能。当您调用ZipInputStream.getNextEntry()时,它将流定位在下一个数据条目的开头,在这种情况下,当您需要数据作为子zip文件时,您就需要该数据。流不会超过该数据的末尾,因此不必担心读入下一个条目,ZipInputStream.getNextEntry()的条目从本质上可以像它们自己的单独流一样对待。

ZipInputStream
© www.soinside.com 2019 - 2024. All rights reserved.