Java Unzip to Folder unzip(String filePath, String unzipPath)

Here you can find the source of unzip(String filePath, String unzipPath)

Description

unzip

License

Open Source License

Declaration

@SuppressWarnings("rawtypes")
    public static void unzip(String filePath, String unzipPath) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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 {
    @SuppressWarnings("rawtypes")
    public static void unzip(String filePath, String unzipPath) {
        Enumeration entries;//from   w  w w. jav a2  s  . com
        ZipFile zipFile;
        BufferedOutputStream out = null;
        try {
            zipFile = new ZipFile(filePath);
            entries = zipFile.entries();
            while (entries.hasMoreElements()) {
                ZipEntry entry = (ZipEntry) entries.nextElement();
                if (entry.isDirectory() || entry.getName().startsWith("META-INF")) {
                    continue;
                }
                out = new BufferedOutputStream(new FileOutputStream(unzipPath + entry.getName()));
                byte[] buffer = new byte[1024];
                int len;
                while ((len = zipFile.getInputStream(entry).read(buffer)) >= 0) {
                    out.write(buffer, 0, len);
                }
            }
            zipFile.close();
            out.close();
        } catch (Exception ioe) {
            ioe.printStackTrace();
            return;
        }
    }
}

Related

  1. unzip(String archive, String out_dir)
  2. unZip(String baseDir, InputStream is)
  3. unzip(String compressedStr)
  4. unzip(String file, String destinationdir)
  5. unzip(String inFilePath)
  6. unzip(String inFilePath, String outFilePath)
  7. unzip(String inputZipPath, String destinationDirectory)
  8. unzip(String path, int buffer)