Java Unzip ZipEntry unzipEntryToFolder(ZipEntry entry, InputStream zis, File destFolder)

Here you can find the source of unzipEntryToFolder(ZipEntry entry, InputStream zis, File destFolder)

Description

unzip Entry To Folder

License

Apache License

Declaration

public static File unzipEntryToFolder(ZipEntry entry, InputStream zis, File destFolder)
            throws FileNotFoundException, IOException 

Method Source Code

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

import java.io.BufferedOutputStream;

import java.io.File;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.ZipEntry;

public class Main {
    private static int BUFFER = 2048;

    public static File unzipEntryToFolder(ZipEntry entry, InputStream zis, File destFolder)
            throws FileNotFoundException, IOException {
        BufferedOutputStream dest;
        if (entry.isDirectory()) {
            File destFile = new File(destFolder, entry.getName());
            destFile.mkdirs();//from w w  w . ja  v  a  2s . c  om
            return destFile;
        } else {
            int count;
            byte data[] = new byte[BUFFER];
            // write the files to the disk
            File destFile = new File(destFolder, entry.getName());
            File parentFolder = destFile.getParentFile();
            if (!parentFolder.exists())
                parentFolder.mkdirs();
            FileOutputStream fos = new FileOutputStream(destFile);
            dest = new BufferedOutputStream(fos, BUFFER);
            while ((count = zis.read(data, 0, BUFFER)) != -1) {
                dest.write(data, 0, count);
            }
            dest.flush();
            dest.close();

            return destFile;
        }
    }
}

Related

  1. unzipEntry(ZipFile zipfile, ZipEntry entry, File outputDirectory)
  2. unzipEntry(ZipInputStream zin, File f)
  3. unzipEntry(ZipInputStream zis, File newFile)
  4. unzipEntry(ZipInputStream zis, File out)
  5. unzipEntry(ZipInputStream zis, File targetFile)
  6. unZipFile(File destFile, ZipFile zipFile, ZipEntry entry)
  7. unzipFile(ZipFile archive, File targetFile, ZipEntry entry)
  8. unzipSingleEntry(ZipInputStream zin, File toFile)