Java Unzip File unzip(File zipFile, File destination)

Here you can find the source of unzip(File zipFile, File destination)

Description

unzip

License

Open Source License

Declaration

public static void unzip(File zipFile, File destination) throws IOException 

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.ZipFile;

public class Main {
    public static void unzip(File zipFile, File destination) throws IOException {
        ZipFile zip = new ZipFile(zipFile);

        destination.mkdir();/*www .  j ava 2  s  . co  m*/
        Enumeration zipFileEntries = zip.entries();

        while (zipFileEntries.hasMoreElements()) {
            ZipEntry entry = (ZipEntry) zipFileEntries.nextElement();
            String currentEntry = entry.getName();
            File destFile = new File(destination, currentEntry);
            File destinationParent = destFile.getParentFile();
            destinationParent.mkdirs();

            if (!entry.isDirectory()) {
                BufferedInputStream is = new BufferedInputStream(zip.getInputStream(entry));
                int currentByte;
                byte data[] = new byte[2048];
                FileOutputStream fos = new FileOutputStream(destFile);
                BufferedOutputStream dest = new BufferedOutputStream(fos, 2048);
                while ((currentByte = is.read(data, 0, 2048)) != -1) {
                    dest.write(data, 0, currentByte);
                }
                dest.flush();
                dest.close();
                is.close();
            }
        }
    }
}

Related

  1. unzip(File zipFile, File destDir)
  2. unzip(File zipFile, File destDir)
  3. unzip(File zipFile, File destDir)
  4. unzip(File zipFile, File destDir)
  5. unzip(File zipFile, File destDir)
  6. unzip(File zipFile, File destination, IProgressMonitor monitor)
  7. unzip(File zipfile, File directory)
  8. unzip(File zipfile, File directory)
  9. unzip(File zipFile, File outputDir)