Java Unzip File unzip(File destDir, InputStream is)

Here you can find the source of unzip(File destDir, InputStream is)

Description

unzip

License

Open Source License

Declaration

public static void unzip(File destDir, InputStream is) 

Method Source Code

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

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

import java.io.FileOutputStream;

import java.io.InputStream;

import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

public class Main {
    public static void unzip(File destDir, InputStream is) {
        final int BUFFER = 2048;
        try {//from   w  w  w .  j  a v  a  2  s .co  m
            BufferedOutputStream dest = null;
            ZipInputStream zis = new ZipInputStream(is);
            ZipEntry entry;
            while ((entry = zis.getNextEntry()) != null) {
                //System.out.println("Extracting: " + entry);

                File destinationFilePath = new File(destDir, entry.getName());
                // create directories if required.
                destinationFilePath.getParentFile().mkdirs();

                if (!entry.isDirectory()) {
                    int count;
                    byte data[] = new byte[BUFFER];
                    // write the files to the disk
                    FileOutputStream fos = new FileOutputStream(destinationFilePath);
                    dest = new BufferedOutputStream(fos, BUFFER);
                    while ((count = zis.read(data, 0, BUFFER)) != -1) {
                        dest.write(data, 0, count);
                    }
                    dest.flush();
                    dest.close();
                }
            }
            zis.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Related

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