Java Unzip File unZip(File zipFile, String extPlace, boolean reservZipFile)

Here you can find the source of unZip(File zipFile, String extPlace, boolean reservZipFile)

Description

un Zip

License

Open Source License

Declaration

public static void unZip(File zipFile, String extPlace, boolean reservZipFile) throws IOException 

Method Source Code

//package com.java2s;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

import java.io.IOException;
import java.io.OutputStream;

import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

public class Main {

    public static void unZip(File zipFile, String extPlace, boolean reservZipFile) throws IOException {
        ZipInputStream in = new ZipInputStream(new FileInputStream(zipFile));
        ZipEntry entry = null;//ww  w .j a va 2s  .c  om
        while ((entry = in.getNextEntry()) != null) {
            String entryName = entry.getName();
            if (entry.isDirectory()) {
                File file = new File(extPlace + entryName);
                file.mkdirs();
            } else {
                File file = new File(extPlace + entryName);
                if (!file.isFile()) {
                    file = file.getAbsoluteFile();
                    File parent = file.getParentFile();
                    if (!parent.exists()) {
                        parent.mkdirs();
                    }
                }
                OutputStream os = new FileOutputStream(extPlace + entryName);
                byte[] buf = new byte[1024];
                int len;
                while ((len = in.read(buf)) > 0) {
                    os.write(buf, 0, len);
                }
                os.close();
                in.closeEntry();
            }
        }
        in.close();
        if (!reservZipFile) {
            zipFile.delete();
        }
    }
}

Related

  1. unzip(File zipfile, File directory)
  2. unzip(File zipfile, File directory)
  3. unzip(File zipFile, File outputDir)
  4. unzip(File zipFile, File outputFolder)
  5. unZip(File zipFile, String desdir)
  6. unzip(File zipFileName, File targetDir)
  7. unzip(File zipName, File destDir)
  8. unZip(File zipPath, File destPath)
  9. unzip(File zippedFile)