Android™
Android™
Unzip all Files to a Single Directory (Ignoring Subdirectories in Zip)
See more Zip Examples
Demonstrates how to unzip all files into a single directory, ignoring the internal directory structure of the files in the .zip.Chilkat Android™ Downloads
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;
import android.app.Activity;
import com.chilkatsoft.*;
import android.widget.TextView;
import android.os.Bundle;
public class SimpleActivity extends Activity {
private static final String TAG = "Chilkat";
// Called when the activity is first created.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
boolean success = false;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
String outDir = "c:/temp/testUnzipDir";
// Make sure our output directory exists.
CkFileAccess fac = new CkFileAccess();
success = fac.DirEnsureExists(outDir);
if (success == false) {
Log.i(TAG, fac.lastErrorText());
return;
}
CkZip zip = new CkZip();
// In this example, the xml_files.zip contains some files in the subdirectories "dir1" and also "dir2/dir3".
// a1.xml
// b1.xml
// c1.xml
// dir1/a2.xml
// dir1/c2.xml
// dir2/dir3/c3.xml
success = zip.OpenZip("qa_data/zips/xml_files.zip");
if (success == false) {
Log.i(TAG, zip.lastErrorText());
return;
}
// Unzip all files into the directory c:/temp/testUnzipDir
int numUnzipped = zip.UnzipInto(outDir);
if (numUnzipped < 0) {
Log.i(TAG, zip.lastErrorText());
return;
}
Log.i(TAG, "Num unzipped = " + String.valueOf(numUnzipped));
// After unzipping via UnzipInto, we have this:
// c:\temp\testUnzipDir\a1.xml
// c:\temp\testUnzipDir\b1.xml
// c:\temp\testUnzipDir\c1.xml
// c:\temp\testUnzipDir\a2.xml
// c:\temp\testUnzipDir\c2.xml
// c:\temp\testUnzipDir\c3.xml
zip.CloseZip();
Log.i(TAG, "Success.");
}
static {
System.loadLibrary("chilkat");
// Note: If the incorrect library name is passed to System.loadLibrary,
// then you will see the following error message at application startup:
//"The application <your-application-name> has stopped unexpectedly. Please try again."
}
}