• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to append a file to an existing zip file

 
Srini vempuluru
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to append a file to an existing zip file using ZipOutputStream. Please provide some sample code to do that. I used the following code.
BufferedInputStream fileNameToBeAppended= new BufferedInputStream(
new FileInputStream(tempFileName), BUFFER);
ZipOutputStream zipOS = new ZipOutputStream(
new FileOutputStream(TotalZip.zip",true));
zipFile = new ZipEntry(tempFileName);
zipOS.putNextEntry(zipFile);
int count;
while ((count = bis.read(data, 0, BUFFER)) != -1) {
zipOS.write(data, 0, count);
}
bis.close();
The above code is overriding the existing zip file with the new file instead of appending.
Thanks,
Srini
 
Billybob Marshall
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Srinivasulu Vempuluru:
The above code is overriding the existing zip file with the new file instead of appending.
[/QB]

That's the only thing it could do. You can't modify a ZIP - they are always re-written.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!