• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

How to append a file to an existing zip file

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic