• Post Reply Bookmark Topic Watch Topic
  • New Topic

Updating ONE entry in a ZIP file

 
Florent Georges
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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/
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • 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.
 
Rob Spoor
Sheriff
Posts: 20822
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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/
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!