Name: krT82822 Date: 05/01/99
I'm sure this is well known already, so it's not really a
bug, but it is definitely a pain.
Here's code explaining the problem:
// If I open a ZipOutputStream based on an existing File
ZipOutputStream zip = new ZipOutputStream(
new BufferedOutputStream(
new FileOutputStream(
new File( existingFileNameString ) ) ) );
// and try to write additional data to it
ZipEntry entry = new ZipEntry( "Another entry" );
zip.putNextEntry( entry );
zip.write( ( "StuffIWantToWrite" ).getBytes() );
zip.closeEntry();
zip.close();
// Then I get ZipExceptions 'duplicate entry'.
// This is no surprise.
// But even if I open the ZipOutputStream with the
// underlying FileOuputStream in append mode:
ZipOutputStream zip = new ZipOutputStream(
new BufferedOutputStream(
new FileOutputStream( existingFileNameString, true ) ) );
// ... then I get no Exceptions, but the resulting zip
// archive is no good.
What I think happens (I know nothing about the zip format,
so this is a guess) is that the end of the file is found and the
data appended, but the previous zip index data is not read and
updated correctly. This is borne out by the way that the zip
gets corrupted ie the file size increases by about the amount I
would expect, but only the entries appended are correctly
indexed. This means I can no longer get at the data originally
in the archive.
(Review ID: 57632)
======================================================================
- duplicates
-
JDK-4129445 An API to incrementally update ZIP files
-
- Closed
-