Home > Home > Decompress file using Zip utility

Decompress file using Zip utility

As I mentioned in previous post about compressing file using Zip utility, so there should be a way to de-compress zip files, too.

Here is the sample usage:

1. Utils.java

	 * to decompress file zip
	 * @param	zipFile		the target ZIP file to unzip
	 * @param	pathToUnzip	where unzipped file to be stored
	public static void decompress(String zipFile, String pathToUnzip) {

		try {
			ZipInputStream zipIn = new ZipInputStream(new FileInputStream(zipFile));
			ZipEntry entry = null;
			while((entry = zipIn.getNextEntry()) != null) {
				if(!entry.isDirectory()) {
					FileOutputStream fout = new FileOutputStream(pathToUnzip + "/" + entry.getName());
					for(int c = zipIn.read(); c != -1; c = zipIn.read()) {

		} catch (Exception ex) {
			Log.d("Error", ex.getMessage());

2. MainScreen.java

package pete.apps.samples.compressionzip;

import android.app.Activity;
import android.os.Bundle;
import pete.apps.samples.compressionzip.Utils;

public class MainScreen extends Activity
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState)


    public void doDecompress() {
    	final String DIR_TARGET = "/sdcard/Download/Unzip";
    	final String FILE_ZIP = "/sdcard/Download/target.zip";

    	Utils.decompress(FILE_ZIP, DIR_TARGET);

– Note  that if inside the Zip file containing also directories, then you need to check whether the __ZipEntry__ queried from ZIP file is a directory or not to create an equivalent directory while unzipping files; then just output files from zip package as normal.



Pete Houston

Categories: Home Tags: , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: