Java Unzip File unzip(File archiveFile, File destination)

Here you can find the source of unzip(File archiveFile, File destination)

Description

unzip

License

Apache License

Declaration

public static void unzip(File archiveFile, File destination) throws Exception 

Method Source Code


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

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

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

public class Main {
    private static final int BUFFER = 2048;

    public static void unzip(File archiveFile, File destination) throws Exception {
        try {/*  w w  w  .ja va 2s.  co  m*/
            BufferedOutputStream dest = null;
            FileInputStream fis = new FileInputStream(archiveFile);
            ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis));
            ZipEntry entry;
            File base = destination;

            while ((entry = zis.getNextEntry()) != null) {
                int count;
                byte data[] = new byte[BUFFER];
                File file = new File(base, entry.getName());
                if (entry.getName().endsWith("/")) {
                    file.mkdirs();
                    continue;
                }
                if (file.getParentFile() != null && !file.getParentFile().exists())
                    file.getParentFile().mkdirs();
                FileOutputStream fos = new FileOutputStream(file);
                dest = new BufferedOutputStream(fos, BUFFER);
                while ((count = zis.read(data, 0, BUFFER)) != -1) {
                    dest.write(data, 0, count);
                }
                dest.flush();
                dest.close();
            }
            zis.close();
            fis.close();
        } catch (Exception e) {
            throw e;
        }
    }
}

Related

  1. uncompressZipEntry(ZipInputStream zis, ZipEntry zipEntry, String dest)
  2. unzip(File aFile)
  3. unzip(File archive)
  4. unzip(File archive, File output)
  5. unzip(File archiveFile, File destination)
  6. unzip(File archiveFile, File targetDir, boolean skipRoot)
  7. unzip(File dest, String jar)
  8. unzip(File destDir, InputStream is)
  9. unzip(File epubfile, File destination)