Here you can find the source of unpackZip(Context context, String s, InputStream is)
Parameter | Description |
---|---|
context | is the context of the application |
s | is the series, for creating a dir named as its ID |
is | is the InputStream representig the zip file to unpack |
public static boolean unpackZip(Context context, String s, InputStream is)
//package com.java2s; import java.io.BufferedInputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import android.content.Context; public class Main { /**//from w w w . j a v a 2s . c o m * Unpack the given InputStream, representing ZIP file, to app cache dir * * @param context * is the context of the application * @param s * is the series, for creating a dir named as its ID * @param is * is the InputStream representig the zip file to unpack * @return true if operation is successful, false otherwise */ public static boolean unpackZip(Context context, String s, InputStream is) { ZipInputStream zis; try { String filename; File cache = context.getCacheDir(); File dir = new File(cache.getAbsolutePath() + "/" + s); dir.mkdir(); zis = new ZipInputStream(new BufferedInputStream(is)); ZipEntry ze; byte[] buffer = new byte[1024]; int count; while ((ze = zis.getNextEntry()) != null) { filename = ze.getName(); // Need to create directories if not exists, or // it will generate an Exception... if (ze.isDirectory()) { File fmd = new File(dir.getAbsolutePath() + filename); fmd.mkdirs(); continue; } FileOutputStream fout = new FileOutputStream( dir.getAbsolutePath() + "/" + filename); while ((count = zis.read(buffer)) != -1) { fout.write(buffer, 0, count); } fout.close(); zis.closeEntry(); } zis.close(); } catch (IOException e) { e.printStackTrace(); return false; } return true; } }