Java Unzip to Folder unzip(String zip, String path)

Here you can find the source of unzip(String zip, String path)

Description

unzip

License

MIT License

Declaration

public static void unzip(String zip, String path) throws IOException, FileNotFoundException 

Method Source Code

//package com.java2s;
/*//from  w w w. j av  a 2s .c om
 * Copyright 2010-2011, Sikuli.org
 * Released under the MIT License.
 *
 */

import java.io.*;

import java.util.zip.*;

public class Main {
    public static void unzip(String zip, String path) throws IOException, FileNotFoundException {
        final int BUF_SIZE = 2048;
        FileInputStream fis = new FileInputStream(zip);
        ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis));
        ZipEntry entry;
        while ((entry = zis.getNextEntry()) != null) {
            int count;
            byte data[] = new byte[BUF_SIZE];
            FileOutputStream fos = new FileOutputStream(new File(path, entry.getName()));
            BufferedOutputStream dest = new BufferedOutputStream(fos, BUF_SIZE);
            while ((count = zis.read(data, 0, BUF_SIZE)) != -1) {
                dest.write(data, 0, count);
            }
            dest.close();
        }
        zis.close();
    }

    public static String getName(String filename) {
        File f = new File(filename);
        return f.getName();
    }
}

Related

  1. unzip(String src, String dest, PrintStream stream)
  2. unzip(String sZip)
  3. unzip(String toUnpackName)
  4. unzip(String zip, String dest)
  5. unzip(String zip, String folder)
  6. unzip(String zip, String unzipDir, int bufferSize)
  7. Unzip(String zipFile, String outputDirectory)
  8. unzip(String zipFile, String targetFolder)
  9. unzip(String zipFile, String targetFolder, String... fileSuffixes)