Java Unzip File unzip(File inputFile, File outputDir)

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

Description

unzip

License

LGPL

Declaration

public static void unzip(File inputFile, File outputDir) throws IOException 

Method Source Code


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

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 inputFile, File outputDir) throws IOException {
        ZipInputStream zis = new ZipInputStream(new FileInputStream(inputFile));
        ZipEntry ze = zis.getNextEntry();
        while (ze != null) {
            String entryName = ze.getName();
            File f = new File(outputDir + File.separator + entryName);
            f.getParentFile().mkdirs();//  w w  w.ja va2s  .  c  om
            FileOutputStream fos = new FileOutputStream(f);
            int len;
            byte buffer[] = new byte[1024];
            while ((len = zis.read(buffer)) > 0) {
                fos.write(buffer, 0, len);
            }
            fos.close();
            ze = zis.getNextEntry();
        }
        zis.closeEntry();
        zis.close();
    }
}

Related

  1. unzip(File fileToUnzip, File destinationDirectory)
  2. unZip(File inFile, File unzipDir)
  3. unzip(File input)
  4. unzip(File input, File outputDir)
  5. unzip(File input, File outputDirectory)
  6. unzip(File inputFile, File unzipDestFolder)
  7. unzip(File intoFolder, ZipFile zipFile)
  8. unzip(File jar, File target)
  9. unzip(File jarFile, File destDir)