don't dream your life, live your dreams !
If you use maven, add this to your pom.xml :
<dependency> <groupId>net.lingala.zip4j</groupId> <artifactId>zip4j</artifactId> <version>${zip4j.version}</version> </dependency> |
File inputFile = "/var/www/html"; File compressedFile = "/opt/wwwhtml.zip"; String password="mypassword"; ZipParameters parameters = new ZipParameters(); // COMP_DEFLATE is for compression // COMp_STORE no compression parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE); // DEFLATE_LEVEL_ULTRA = maximum compression // DEFLATE_LEVEL_MAXIMUM // DEFLATE_LEVEL_NORMAL = normal compression // DEFLATE_LEVEL_FAST // DEFLATE_LEVEL_FASTEST = fastest compression parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_ULTRA); // set password : if(password != null) { //Set the encryption flag to true parameters.setEncryptFiles(true); //Set the encryption method to AES Zip Encryption parameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_AES); //AES_STRENGTH_128 - For both encryption and decryption //AES_STRENGTH_192 - For decryption only //AES_STRENGTH_256 - For both encryption and decryption //Key strength 192 cannot be used for encryption. But if a zip file already has a //file encrypted with key strength of 192, then Zip4j can decrypt this file parameters.setAesKeyStrength(Zip4jConstants.AES_STRENGTH_256); //Set password parameters.setPassword(password); } // file compressed zipFile.addFile(inputFile, parameters); |
File compressedFile = "/opt/wwwhtml.zip"; String destination = "/tmp"; String password="mypassword"; ZipFile zipFile = new ZipFile(compressedFile); // If file is encrypted, set password : if (zipFile.isEncrypted()) { zipFile.setPassword(password); } // Extract zip file to destination : zipFile.extractAll(destination); |
Copyright © 2025 My linux world - by Marc RABAHI
Design by Marc RABAHI and encelades.
admin