Thursday, January 6, 2011

How to extract password protected zip file using java program

After the without password zip file extraction process, I start hunting password protected zip file extraction process. After Two days research I found out a web site, which is available free and open source jar file .From that jar file we can extract a password protected zip file. That jar file is zip4j.jar file .you can find out this jar file and it’s information in the following URL.

I have downloaded the zip4j.jar file
And I have implemented the following source code

import net.lingala.zip4j.core.ZipFile;
import net.lingala.zip4j.exception.ZipException;

* @author Administrator
public class Main {

* @param args the command line arguments
public static void main(String[] args) throws IOException {
// TODO code application logic here
ZipFile zipFile = new ZipFile("c:\\zip\\");
// Check to see if the zip file is password protected
if (zipFile.isEncrypted()) {
// if yes, then set the password for the zip file
zipFile.extractFile("29111001.124.txt", "c:\\zip\\12\\");

}catch(ZipException ex){
System.out.println("error "+ ex );

In this program
zip file is available at c:\\zip\\
and extracted file is available at c:\\zip\\12\\ folder
Here "abcd" is the password used to extract zip file.

Note :- i have write down this source code for benefit of all the java programmer.


hengky said...

thanks, really helped me

adrian said...

Thanks for nice and easy code.

aishwarya nv said...

sir above code is not working for me.I am not able to extract the password protected zip file using zip4j