Java Unzip File unzip(File input, File outputDir)

Here you can find the source of unzip(File input, File outputDir)

Description

unzip

License

Open Source License

Declaration

public static void unzip(File input, File outputDir) 

Method Source Code


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

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

public class Main {
    public static void unzip(File input, File outputDir) {
        try {//from  w w w . j  a  v a  2s.  co  m
            if (!outputDir.exists())
                outputDir.mkdir();

            ZipFile zipFile = new ZipFile(input);
            Enumeration e = zipFile.entries();

            while (e.hasMoreElements()) {
                ZipEntry entry = (ZipEntry) e.nextElement();
                File destinationFilePath = new File(outputDir, entry.getName());
                destinationFilePath.getParentFile().mkdirs();
                if (!entry.isDirectory()) {
                    BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(entry));

                    int b;
                    byte buffer[] = new byte[1024];
                    FileOutputStream fos = new FileOutputStream(destinationFilePath);
                    BufferedOutputStream bos = new BufferedOutputStream(fos, 1024);
                    while ((b = bis.read(buffer, 0, 1024)) != -1) {
                        bos.write(buffer, 0, b);
                    }
                    bos.flush();
                    bos.close();
                    bis.close();
                }
            }
        } catch (IOException ioe) {

        }
    }
}

Related

  1. unZip(File file, String outPath, String zipFileName)
  2. unzip(File file, String targetDirectory)
  3. unzip(File fileToUnzip, File destinationDirectory)
  4. unZip(File inFile, File unzipDir)
  5. unzip(File input)
  6. unzip(File input, File outputDirectory)
  7. unzip(File inputFile, File outputDir)
  8. unzip(File inputFile, File unzipDestFolder)
  9. unzip(File intoFolder, ZipFile zipFile)