Java Unzip ZipEntry unzipEntry(ZipFile zipfile, ZipEntry entry, File outputDir)

Here you can find the source of unzipEntry(ZipFile zipfile, ZipEntry entry, File outputDir)

Description

unzip Entry

License

Open Source License

Declaration

private static void unzipEntry(ZipFile zipfile, ZipEntry entry,
            File outputDir) throws IOException 

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.zip.ZipEntry;
import java.util.zip.ZipFile;

public class Main {
    private static void unzipEntry(ZipFile zipfile, ZipEntry entry,
            File outputDir) throws IOException {
        File outputFile = new File(outputDir, entry.getName());

        if (entry.isDirectory()) {
            outputFile.mkdirs();/*w w w .  java  2s  . co  m*/
            return;
        }

        if (!outputFile.getParentFile().exists()) {
            outputFile.getParentFile().mkdirs();
        }

        BufferedInputStream inputStream = new BufferedInputStream(
                zipfile.getInputStream(entry));
        BufferedOutputStream outputStream = new BufferedOutputStream(
                new FileOutputStream(outputFile));

        try {
            byte[] buf = new byte[1024 * 1024];
            int k;
            while ((k = inputStream.read(buf)) != -1) {
                outputStream.write(buf, 0, k);
                outputStream.flush();
            }
        } finally {
            try {
                outputStream.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
            try {
                inputStream.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}

Related

  1. unzipEntry(ZipFile zipFile, ZipEntry entry, File entryTarget)
  2. unzipEntry(ZipFile zipfile, ZipEntry entry, File outputDir)
  3. unzipEntry(ZipFile zipfile, ZipEntry entry, File outputDirectory)
  4. unzipEntry(ZipInputStream zin, File f)
  5. unzipEntry(ZipInputStream zis, File newFile)