私は一方のzipからファイルを取得し、もう一方のzipにファイルを配置するアプリケーションに取り組んでいます。ファイルは問題ありませんが、ソースzipにdirがある場合は、次の例外で失敗します。
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 、Liam