unzip ZipInputStream Entry - Android File Input Output

Android examples for File Input Output:Zip File

Description

unzip ZipInputStream Entry

Demo Code


//package com.java2s;

import java.io.File;

import java.io.FileOutputStream;

import java.util.zip.ZipInputStream;

public class Main {
    private static final int BUFFER_SIZE = 1024 * 2;

    public static File unzipEntry(ZipInputStream zis, File targetFile)
            throws Exception {
        FileOutputStream fos = null;
        try {/* w  w  w  .  j  av  a  2  s  . c  o  m*/
            fos = new FileOutputStream(targetFile);

            byte[] buffer = new byte[BUFFER_SIZE];
            int len = 0;
            while ((len = zis.read(buffer)) != -1) {
                if (len == 0) {
                    return null;
                }
                fos.write(buffer, 0, len);
            }
        } finally {
            if (fos != null) {
                fos.close();
            }
        }
        return targetFile;
    }
}

Related Tutorials