Possible Duplicate:
Appending files to a zip file with Java
Hello Java Developers,
Here's the scenario:
Say I have a textfile named sample.txt
. What I actually want to do is to put the sample.txt
file into a *.zip
file named TextFiles.zip
.
Here's what I have learned so far.
try{
File f = new File(compProperty.getZIP_OUTPUT_PATH());
zipOut = new ZipOutputStream(new FileOutputStream(f));
ZipEntry zipEntry = new ZipEntry("sample.txt");
zipOut.putNextEntry(zipEntry);
zipOut.closeEntry();
zipOut.close();
System.out.println("Done");
} catch ( Exception e ){
// My catch block
}
My code so far creates a *.zip
file and insert the sample.txt
file.
My question is how would I be able to insert an existing file to the created *.zip
file?
If your answer has anything to do with TrueZIP, please post an SSCCE.
I have done the following:
- Googled
- Search for existing question. ( Found few. No answer. Some didn't answer my particular question.
- Read TrueZip. Yet, I couldn't understand a thing. ( Please do understand )
Using the inbuilt Java API. This will add a file to a Zip File, this will replace any existing Zip files that may exist, creating a new Zip file.