Adding to an existing zip file

Can I add to an existing zip file without first reading out its contents? I am using the ZipOutputStream class.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jan LouwerensSoftware EngineerCommented:
yes you can
which compression program do you use?
(WinZip, PKZip, etc...)
cherch0rAuthor Commented:
Edited text of question.
Don't think you can. I have this code from which will encapsulate the process for you and make it a bit easier:

public class ZipAppendWriter {

ZipInputStream zis;
ZipOutputStream zos;
ZipEntry zeIn, zeOut;
File fInfile;
File fOutfile;
String strNewZipFilePath = null;
boolean bInputZipOK = false;

public ZipAppendWriter(String strZipFilePath) throws IOException
byte[] buf;
int iBufLength;

strNewZipFilePath = strZipFilePath;

// Open output
fOutfile = new File(System.currentTimeMillis() +"temp"); // Unique temp filename
zos = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(fOutfile)));

// Open input zip file and read to EOF
fInfile = new File(strZipFilePath);
if (fInfile.isFile())
zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(fInfile)));
bInputZipOK = true;
while ((zeIn = zis.getNextEntry()) != null)
System.out.println("ZE name= " +zeIn.getName() +" size= " +zeIn.getSize());
//buf = new byte[(int) zeIn.getSize()];
buf = new byte[5000000];

// Read the zip entry data
while ((iBufLength = >= 0);

// Write the zip entry to temp output
zeOut = new ZipEntry(zeIn.getName());
zeOut.setSize((long) zeIn.getSize());
System.out.println("ZE name= " +zeIn.getName() +" out setsize= " +zeIn.getSize());
zos.write(buf, 0, (int) zeIn.getSize());

public void write(byte[] baData,
int iOffset,
int iLength,
String strEntryName) throws IOException
zeOut = new ZipEntry(strEntryName);
zeOut.setSize((long) iLength);
System.out.println("ZE Setsize() to " + iLength);
zos.write(baData, iOffset, iLength);

public void close() throws IOException
// Delete the original file
if (bInputZipOK)

// Rename temp to original filename
fOutfile.renameTo(new File(strNewZipFilePath));

public static void main (String args[])
String s = new String("My dog barks then runs away");

long t0 = System.currentTimeMillis();
eSrvZipAppendWriter zfw = new eSrvZipAppendWriter("C:\\test\\");
zfw.write(s.getBytes(), 0, s.length(), "Dogbarks");
catch (IOException ioe)

long t1 = System.currentTimeMillis();
System.out.println("Zip append took " +(t1 - t0) +" milliseconds");

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
agree with Jod

thar's a deep black well ,well kin u jump in without a lookin ?Nah ,u gotta look before ya leeap.

same way here
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.