我工作的應用程序,它從一個壓縮文件需要,並把它們在其他,它的罰款文件,但如果沒有在源目錄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 CEO
哪條線有例外?順便說一句:我也會使用BufferedInputSTream(不是它可以解決問題) – 2012-01-10 10:49:44
at java.util.zip.ZipOutputStream.closeEntry(Unknown Source) \t at com.hachisoftware.mmi.system.Util.ZipExtractToZip(Util。 java:26) – 2012-01-10 10:53:09