Source Code : Decompress a zip file using ZipFile

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

Decompress a zip file using ZipFile

         
 
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

public class Main {
  public static void main(String[] args) throws Exception {
    String zipname = "data.zip";
    ZipFile zipFile = new ZipFile(zipname);
    Enumeration enumeration = zipFile.entries();
    while (enumeration.hasMoreElements()) {
      ZipEntry zipEntry = (ZipEntry) enumeration.nextElement();
      System.out.println("Unzipping: " + zipEntry.getName());
      BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(zipEntry));
      int size;
      byte[] buffer = new byte[2048];
      BufferedOutputStream bos = new BufferedOutputStream(
          new FileOutputStream(zipEntry.getName()), buffer.length);
      while ((size = bis.read(buffer, 0, buffer.length)) != -1) {
        bos.write(buffer, 0, size);
      }
      bos.flush();
      bos.close();
      bis.close();
    }
  }
} 

   
    
    
    
    
    
    
    
    
  

Thank with us