Java Unzip File unZip(File zipFile, String desdir)

Here you can find the source of unZip(File zipFile, String desdir)

Description

un Zip

License

Apache License

Declaration

public static void unZip(File zipFile, String desdir) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.BufferedOutputStream;
import java.io.File;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;

import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

public class Main {
    public static void unZip(File zipFile, String desdir) throws IOException {
        ZipFile zip = new ZipFile(zipFile);
        Enumeration<?> en = zip.entries();
        ZipEntry entry = null;// ww  w .j av  a 2  s. co  m
        byte[] buffer = new byte[8192];
        int length = -1;
        InputStream input = null;
        BufferedOutputStream bos = null;
        File file = null;

        while (en.hasMoreElements()) {
            entry = (ZipEntry) en.nextElement();
            if (entry.isDirectory()) {
                continue;
            }

            input = zip.getInputStream(entry);
            file = new File(desdir, entry.getName());
            if (!file.getParentFile().exists()) {
                file.getParentFile().mkdirs();
            }
            bos = new BufferedOutputStream(new FileOutputStream(file));

            while (true) {
                length = input.read(buffer);
                if (length == -1)
                    break;
                bos.write(buffer, 0, length);
            }
            bos.close();
            input.close();
        }
        zip.close();
    }
}

Related

  1. unzip(File zipFile, File destination, IProgressMonitor monitor)
  2. unzip(File zipfile, File directory)
  3. unzip(File zipfile, File directory)
  4. unzip(File zipFile, File outputDir)
  5. unzip(File zipFile, File outputFolder)
  6. unZip(File zipFile, String extPlace, boolean reservZipFile)
  7. unzip(File zipFileName, File targetDir)
  8. unzip(File zipName, File destDir)
  9. unZip(File zipPath, File destPath)