I am using java’s java.util.zip api to add files and folders to a zip file, but when i add multiple files into the same folder, it deleted the old contents. Is there any way i can add files into the zip file without modifying existing contents in the folder?.
Kindly help, its important!
This is my sample code:
ZipOutputStream zip = null;
FileOutputStream fileWriter = null;
fileWriter = new FileOutputStream(destZipFile);
zip = new ZipOutputStream(fileWriter);
zip.putNextEntry(new ZipEntry(destFilePath));
zip.write(content);
zip.flush();
zip.close();
If you want to add a new file to an existing zip file, you must first unzip everything, then add all the files and zip again.
See this link for samples.