Java Unzip File unZip(File zipPath, File destPath)

Here you can find the source of unZip(File zipPath, File destPath)

Description

un Zip

License

Open Source License

Declaration

public static void unZip(File zipPath, File destPath) throws IOException 

Method Source Code


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

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

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

public class Main {
    public static void unZip(File zipPath, File destPath) throws IOException {
        if (!destPath.exists()) {
            destPath.mkdirs();//from  ww  w. j ava 2s  .  c  o  m
        }
        ZipInputStream in = new ZipInputStream(new FileInputStream(zipPath));
        ZipEntry entry = in.getNextEntry();
        while (entry != null) {
            String filePath = destPath + File.separator + entry.getName();
            if (!entry.isDirectory()) {
                extract(in, filePath);
            } else {
                File dir = new File(filePath);
                dir.mkdir();
            }
            in.closeEntry();
            entry = in.getNextEntry();
        }
        in.close();
    }

    private static void extract(ZipInputStream in, String filePath) throws IOException {
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath));
        byte[] bytes = new byte[4096];
        int read;
        while ((read = in.read(bytes)) != -1) {
            bos.write(bytes, 0, read);
        }
        bos.close();
    }
}

Related

  1. unzip(File zipFile, File outputFolder)
  2. unZip(File zipFile, String desdir)
  3. unZip(File zipFile, String extPlace, boolean reservZipFile)
  4. unzip(File zipFileName, File targetDir)
  5. unzip(File zipName, File destDir)
  6. unzip(File zippedFile)
  7. unzip(File zippedFile, File outputDirectory)
  8. unzip(File zippedFile, File targetDir)
  9. unzip(final byte[] zippedContent)