Android Unzip Folder unZipNoDirs(String file, String destinationDirectory)

Here you can find the source of unZipNoDirs(String file, String destinationDirectory)

Description

extracts a zip archive.

Parameter

Parameter Description
argv a parameter

Exception

Parameter Description
IOException an exception

Declaration

public static void unZipNoDirs(String file, String destinationDirectory)
        throws IOException 

Method Source Code

//package com.java2s;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;

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 {
    /**//from   ww  w.  j  a va  2  s  .  c o  m
     * extracts a zip archive. Does not handle directories
     * kudos: http://java.sun.com/developer/technicalArticles/Programming/compression/
     * @param argv
     * @throws IOException 
     */
    public static void unZipNoDirs(String file, String destinationDirectory)
            throws IOException {
        final int BUFFER = 2048;
        BufferedOutputStream dest = null;
        FileInputStream fis = new FileInputStream(file);
        ZipInputStream zis = new ZipInputStream(
                new BufferedInputStream(fis));
        ZipEntry entry;
        while ((entry = zis.getNextEntry()) != null) {
            int count;
            byte data[] = new byte[BUFFER];
            // write the files to the disk
            String destinationFilename = destinationDirectory
                    + File.separator + entry.getName();
            FileOutputStream fos = new FileOutputStream(destinationFilename);
            dest = new BufferedOutputStream(fos, BUFFER);
            while ((count = zis.read(data, 0, BUFFER)) != -1) {
                dest.write(data, 0, count);
            }
            dest.flush();
            dest.close();
        }
        zis.close();
    }
}

Related

  1. UnZipFolder(String zipFileString, String outPathString)
  2. UnzipSubDir(InputStream is, String subdir, String targetPath)
  3. UnzipSubDir(String source, String subdir, String targetPath)
  4. unZipFolder(InputStream zipFileStream, String outPathString)
  5. unZipFolder(InputStream zipFileStream, String outPathString)