我正在处理一个应用程序,该应用程序将文件从一个zip中提取并放入另一个zip中,对于文件来说一切正常,但如果源Zip中有目录,则会出现以下异常:
Exception in thread "main" java.util.zip.ZipException: invalid entry size (expected 1374 but got 1024 bytes)
我正在使用以下代码:
public static void ZipExtractToZip(File inZip, File outZip) throws IOException
{
ZipInputStream zis = new ZipInputStream(new FileInputStream(inZip));
ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(outZip)));
byte[] buffer = new byte[1024];
for (ZipEntry ze = zis.getNextEntry(); ze != null; ze = zis.getNextEntry())
{
zos.putNextEntry(ze);
for (int read = zis.read(buffer); read != -1; read = zis.read(buffer)) {
zos.write(buffer, 0, read);
}
zos.closeEntry();
}
zos.close();
zis.close();
}
我尝试了不同的缓冲区大小,但这并没有起到帮助作用,我需要一种获取动态缓冲区大小的方法。欢迎提供示例和链接。
编辑:我已更改代码以使其可用。
- 列姆,Hachi Software首席执行官