我想解压缩使用 Windows 10 的压缩功能创建的 .zip 文件(其中包含 .jpg 文件)。
首先我用Java 8的本机测试了它,util.zip.ZipEntry
但一直invalid CEN header (bad compression method)
报错,这似乎是由于与Win10的压缩不兼容造成的。
因此,我切换到 Apache Common 的Compress
库(1.2 版)。存档中的前两个图像解压缩正常,但第三个总是抛出异常:
org.apache.commons.compress.archivers.zip.UnsupportedZipFeatureException: 条目 image3.jpg 中使用的不支持的压缩方法 14 (LZMA)
如何使用Compress
库完全解压缩此存档?这甚至可能吗?
我的代码:
ZipFile z = new ZipFile(zippath);
Enumeration<ZipArchiveEntry> entries = z.getEntries();
while(entries.hasMoreElements()) {
ZipArchiveEntry entry = entries.nextElement();
System.out.println("Entry: "+entry.getName());
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(unzipfolder+"\\"+entry.getName()));
BufferedInputStream bis = new BufferedInputStream(z.getInputStream(entry));
byte[] buffer=new byte[1000000];
int len=0;
while((len=bis.read(buffer,0,1000000))>0) {
bos.write(buffer, 0, len) ;
}
bis.close();
bos.close();
}