Java Unzip File unzip(File file, File dest)

Here you can find the source of unzip(File file, File dest)

Description

unzip

License

Open Source License

Declaration

public static void unzip(File file, File dest) throws IOException, ZipException 

Method Source Code


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

import java.io.*;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;

public class Main {
    public static void unzip(File file, File dest) throws IOException, ZipException {
        ZipFile zipFile = new ZipFile(file);
        Enumeration<? extends ZipEntry> entries = zipFile.entries();
        while (entries.hasMoreElements()) {
            ZipEntry entry = entries.nextElement();
            File entryDest = new File(dest, entry.getName());
            if (entry.isDirectory()) {
                entryDest.mkdir();//from w  ww  . ja va  2s  .c om
            } else {
                entryDest.getParentFile().mkdirs();
                BufferedInputStream bin = new BufferedInputStream(zipFile.getInputStream(entry));
                int length;
                BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(entryDest));
                while ((length = bin.read()) != -1) {
                    bout.write(length);
                }
                bout.close();
            }
        }
    }
}

Related

  1. unzip(File archiveFile, File destination)
  2. unzip(File archiveFile, File targetDir, boolean skipRoot)
  3. unzip(File dest, String jar)
  4. unzip(File destDir, InputStream is)
  5. unzip(File epubfile, File destination)
  6. unzip(File file, File destDir)
  7. unzip(File file, File directory)
  8. unzip(File file, File targetDirectory)
  9. unzip(File file, File targetDirectory)