/java/

Zip4j, add file to existing zip file.

2013-07-17 20:54:21

maven


<dependency>
<groupid>net.lingala.zip4j</groupid>
<artifactid>zip4j</artifactid>
<version>1.3.1</version>
</dependency>

example

ZipFile zipFile = new ZipFile(new File("/home/szalek/zip/core1.zip"));

ArrayList filesToAdd = new ArrayList();
filesToAdd.add(new File("/home/szalek/zip/someData.txt"));

ZipParameters parameters = new ZipParameters();
parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);

//password
parameters.setEncryptFiles(true);
parameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_STANDARD);
parameters.setPassword("test123!");
//password

zipFile.addFiles(filesToAdd, parameters);