• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Updating ONE entry in a ZIP file

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a ZIP file within which I have to change only one
entry. Unfortunately, I don't see how to achieve this goal
using the java.util.zip package. Is this possible in standard
Java SE? Or using a third party library?

Regards,

--
Florent Georges
http://www.fgeorges.org/
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

The java.util.zip package has no provisions for modifying zip files; it can read or write them, but not update them. So one approach would be to read the complete file, write everything that's read to a different file, and make the changes you need to make where appropriate during the writing. Afterwards, if the new file was created successfully, you can rename the old file to something else, and then rename the new one to have the old one's name.
 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's also a technique several ZIP programs use themselves. I know one created a file ending with ZI# instead of ZIP, then when it was ready it removed the original and renamed the ZI# to ZIP.
 
Florent Georges
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks to both of you for your response. That's what I was afraid of. It sounds like a waste of resource to me because AFAIK the ZIP format compress each entry individually (in contrary to .tar.gz for instance.) But well, if I do not have the choice...

Maybe you know a good library for more complex ZIP handling?

Regards,

--
Florent Georges
http://www.fgeorges.org/
reply
    Bookmark Topic Watch Topic
  • New Topic