Java Unzip to Folder unzipFile(String zipFile, String extDir)

Here you can find the source of unzipFile(String zipFile, String extDir)

Description

unzip File

License

Open Source License

Declaration

public static void unzipFile(String zipFile, String extDir) 

Method Source Code


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

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

public class Main {
    private static final int BUFSIZE = 4096;

    public static void unzipFile(String zipFile, String extDir) {
        File f = new File(zipFile);
        try {/*from  w w w.ja va2s  . co m*/
            FileInputStream fi = new FileInputStream(f);
            ZipInputStream zipInput = new ZipInputStream(fi);
            ZipEntry zip = zipInput.getNextEntry();
            while (zip != null) {
                File fo = new File(extDir + "/" + zip.getName());
                FileOutputStream fout = new FileOutputStream(fo);
                byte inbuf[] = new byte[BUFSIZE];
                int n = 0;
                while ((n = zipInput.read(inbuf, 0, BUFSIZE)) != -1) {
                    fout.write(inbuf, 0, n);
                }
                fout.close();
                zip = zipInput.getNextEntry();
            }
            zipInput.close();
            fi.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Related

  1. unzip(String zipFileName, String outputDirectory)
  2. unzip(String zipFileName, String targetFolderPath)
  3. unzip(String zipFileName, String targetPath)
  4. unzip(String zipFileName, String unzipdir)
  5. unzipFile(String zipFile, File outputFolder)
  6. unZipFile(String zipFile, String outputFolder)
  7. unzipFile(String zipFile, String outputFolder)
  8. unzipFile(String zipFileName, String outputDir)
  9. unzipFile(String zipFilePath, String releasePath)