![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java JavaScript Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Android™) Unzip an Entire ZIP Archive While Preserving Directory StructureSee more Zip ExamplesExtract an Entire ZIP Archive While Preserving Directory Structure This example demonstrates how to use the The example shows how the stored ZIP directory structure is recreated beneath the target extraction directory. Suppose the ZIP archive contains: After extraction to: The following filesystem structure will be created: If the target extraction directory does not already exist, it is automatically created. The
// 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; CkZip zip = new CkZip(); // Open an existing ZIP archive. success = zip.OpenZip("qa_data/zips/sample.zip"); if (success == false) { Log.i(TAG, zip.lastErrorText()); return; } // ------------------------------------------------------------ // Extract all files to: // // c:/temp/testDir // // If the target directory does not already exist, // Chilkat will automatically create it. // // The Unzip method recreates the stored ZIP directory // structure beneath the target directory. // int numFilesUnzipped = zip.Unzip("c:/temp/testDir"); if (numFilesUnzipped < 0) { Log.i(TAG, zip.lastErrorText()); return; } Log.i(TAG, "Number of files extracted = " + String.valueOf(numFilesUnzipped)); Log.i(TAG, ""); // ------------------------------------------------------------ // Suppose the ZIP archive contains these entries: // // aaa/pigs.json // bbb/base64Cert.txt // bbb/sub1/brasil_cert.pem // bbb/sub2/penguins.gif // bbb/sub2/starfish.jpg // hamlet.xml // hello.pdf // // After extraction, the following files will exist: // // c:/temp/testDir/aaa/pigs.json // c:/temp/testDir/bbb/base64Cert.txt // c:/temp/testDir/bbb/sub1/brasil_cert.pem // c:/temp/testDir/bbb/sub2/penguins.gif // c:/temp/testDir/bbb/sub2/starfish.jpg // c:/temp/testDir/hamlet.xml // c:/temp/testDir/hello.pdf // // The ZIP directory structure is preserved during extraction. // Close the ZIP archive. zip.CloseZip(); Log.i(TAG, "Unzip completed successfully."); } 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." } } |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.