Android Unzip File unpack(File zippedFile, File unpackedFile)

Here you can find the source of unpack(File zippedFile, File unpackedFile)

Description

unpack

Declaration

public static String unpack(File zippedFile, File unpackedFile) 

Method Source Code

//package com.java2s;

import java.io.BufferedInputStream;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Scanner;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

public class Main {
    public static String unpack(File zippedFile, File unpackedFile) {
        long start = System.currentTimeMillis();
        FileInputStream is;/*from   w w w.j  a v a  2 s . c  o m*/
        ZipInputStream zis;
        String content = null;
        try {
            is = new FileInputStream(zippedFile);
            zis = new ZipInputStream(new BufferedInputStream(is));
            ZipEntry ze;
            byte[] buffer = new byte[1024];
            int count;

            while ((ze = zis.getNextEntry()) != null) {
                FileOutputStream fout = new FileOutputStream(unpackedFile);
                while ((count = zis.read(buffer)) != -1) {
                    fout.write(buffer, 0, count);
                }

                fout.close();
                zis.closeEntry();
            }
            zis.close();
            content = new Scanner(unpackedFile).useDelimiter("\\A").next();
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
        long end = System.currentTimeMillis();
        System.out.println("###----> Unpack zip zippedFile, elapsed ms: "
                + (end - start));
        return content;
    }
}

Related

  1. unzip(String zipFile, String location)
  2. unzip(String zipFile, String location)
  3. unzip(String zipFile, String location)
  4. unzip(String zipFile, String location)
  5. unpack(File zippedFile, File unpackedFile)
  6. unpackZip(File zip, String unpackPath)
  7. unpackZip(File zipFile, File location)
  8. unpackZip(String path, String zipname)
  9. unpackZip(String zipFile, String location)