473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Adding new files to Zip archive

I am using the java.util.zip package to create zip files. I can
create a new archive and add files to it without any trouble. But if
I already have a zip file created, how do I add a new file to the
archive without impacting the existing files? I looked through the
APIs with no luck. I would rather avoid extracting all the files and
rebuilding the archive from scratch if at all possible.

Thanks

-M
Jul 17 '05 #1
1 10333
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Aladdin wrote:
I am using the java.util.zip package to create zip files. I can
create a new archive and add files to it without any trouble. But
if I already have a zip file created, how do I add a new file to the
archive without impacting the existing files? I looked through the
APIs with no luck. I would rather avoid extracting all the files
and rebuilding the archive from scratch if at all possible.

Thanks

-M


Hi,
I'm not familiar with the internal format of a ZIP file, but
rebuilding the file from scratch may be the only way any program can
do it. I'm not sure. I was interested, so I created a ZIP with two
files in it just now to look at. It seems that the files' data is
placed, along with the filenames, into the ZIP, and that immediately
following the last file is a table of contents with all the
filenames. This would imply that you cannot add data to a ZIP without
at least loading the table of contents, overwriting it, and rewriting
it at the new end of file. Anyway, if nobody comes up with a better
solution, remember that it's probably better to create a new,
temporary ZIP file, then transfer all the files via an in-memory
array from the old to the new, followed by finally placing your new
file in the new ZIP. This is probably faster than the other option,
which would be extracting all the contents of the old ZIP to actual
files, deleting it, then replacing it.

- --
Chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE/RTDxwxczzJRavJYRAlh0AKD27GEvLcI/Fg+jHYpiBYpndnKb/ACfcS7t
cZrygAi8TLOh18IbgYcU7c0=
=F5kv
-----END PGP SIGNATURE-----
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Hal Vaughan | last post by:
I am using OpenOffice files in my app. They're stored in .zip format, so the zip format is much more important, in this case, than that they're OOo files (other than that the extension is .sxw and...
4
by: Hal Vaughan | last post by:
I am writing out archive files using ZipOutputStream with the following code: aEntry is a global Array of ZipEntries llData is a LinkedList of the data corresponding to the the ZipEntry of the...
17
by: Lonnie Princehouse | last post by:
In short: Is there any way to run Python WITHOUT trying to create .pyc files (or ..pyo) or to have Python not attempt to import the .pyc files it finds? Reason: We have a site-specific...
1
by: Lorenzo Mugnai | last post by:
Hi everyone, Below is my code which basically opens a file and appends some text if the file is below a certain size, if not it archives the file and begins a new one. The problem is i have four...
6
by: JezB | last post by:
From a windows application, I want to provide an "archive" facility which will scan a specific directory and put specific files into some single "Archive file", a bit like a zip-file I guess, but...
10
by: joelagnel | last post by:
hi friends, i've been having this confusion for about a year, i want to know the exact difference between text and binary files. using the fwrite function in c, i wrote 2 bytes of integers in...
1
by: Piet | last post by:
I've been trying to use PCLzip to extract uploaded archives with the following code: $archive = new PclZip('temp/temp.zip'); if ($archive->extract(PCLZIP_OPT_PATH, 'temp/') == 0) { die("Error :...
3
by: aRTx | last post by:
I have try a couple of time but does not work for me My files everytime are sortet by NAME. I want to Sort my files by Date-desc. Can anyone help me to do it? The Script <? /* ORIGJINALI
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.