Friday, 30 May 2014

how to unzip a password protected zip file using java?



You can Do this By using the Zip4j open source API for java.
For this you required a jar file zip4j_1.3.2.


Download The Jar
   https://sites.google.com/site/thinkincomputerblogspotcom/zip4j-1-3-2-jar/zip4j_1.3.2.jar?attredirects=0&d=1


Java Program is:

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



public class UnzipafileUsingPassword {

/**
* @Author=AJAY 
          * @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

   String source = "F:/Zeta1.zip";
String destination = "F:/";
String password = "AJAY";
System.out.println("AJAY");

try
{
  ZipFile zipFile = new ZipFile(source);
   if (zipFile.isEncrypted()) {
       zipFile.setPassword(password);    
       }
   zipFile.extractAll(destination);
}
catch(ZipException e)
{
e.printStackTrace();
}

}

}

No comments: