tags:

views:

742

answers:

3

I'd like to use the ZipFile class to unzip a file using it's name from an archive of multiple files. How can I get the String of the zip file name and directory to pass to the ZipFile constructor?

A: 

You can use the AssetManager and ZipInputStream http://developer.android.com/reference/android/content/res/AssetManager.html

ZipInputStream in = null;
try {
    final String zipPath = "data/sample.zip";
    // Context.getAssets()
    in = new ZipInputStream(getAssets().open(zipPath));
    for (ZipEntry entry = in.getNextEntry(); entry != null; entry = in.getNextEntry()) {
        // handle the zip entry
    }
} catch (IOException e) {
    Log.e(TAG, e.getMessage());
} finally {
    try {
        if (in != null) {
            in.close();
        }
    } catch (IOException ignored) {
    }
    in = null;
}
qrtt1
A: 

can you provide the code snippet to extract seperate files and their contents from a zip file ?

Kartik
A: 

Using the above code i couldnot unzip a file which contain folders

Debabrata