
Use the Zip4j library for zip files or streams in Delphi and C++ Builder to fully handle zip files in your FireMonkey project easily. Zip4j has several major features for instance: Zip encryption, Support for Zip64 format, support for streams, support for both AES and Zip-Standard encryption methods, and many more.
To utilize this Zip4j library in your Delphi and C++ Builder FireMonkey projects you can use Zip for Android library from WINSOFT. This is a commercial library that has a trial version with all features for evaluation only and if you wish to distribute Zip for Android library as part of your Android application, you must register a license.
You should know that you can utilize this Zip4j library directly by creating a module yourself to call its functions from your Delphi code. But the Zip for Android library has already implemented all the needed modules to you. It means in a little amount of time you can utilize Zip4j functionalities without creating modules.
With this Zip for Android library, you can create, add, extract, update, and remove files from a Zip file with Zip Parameters. Moreover, you can get zip file header data easily to learn Zip file configurations.
Let’s investigate the features of the Zip for Android library. The first step is to install the library itself into your IDE. Here is the short tutorial on installing the library.
The next step is to add the zip4j-2.5.3-SNAPSHOT.jar file into your Android 32-bit library list by add option here:

Result:

User interface:

So, you can watch this short video showing the demo in action or you can just follow this article and learn the main features and use cases of the Zip for Android library.
Here are our helper functions:
1 2 3 4 5 |
private { Private declarations } function FileName(Index: Integer): String; function FileContent(Index: Integer): String; function ZippedFileName: String; |
- FileName function gets the Full Path of the file
- FileContent function returns string data
- ZippedFileName function returns the zipped file path
To utilize Zip for Android library we should add Winsoft.Android.Zip unit to uses section with other units:
1 2 |
uses Winsoft.Android.Zip, Androidapi.Helpers, Androidapi.JNI.JavaTypes, System.IOUtils, Posix.Unistd; |
Now, we can discover how this library is creating Zip files.
1 2 3 4 |
var ZipParameters: JZipParameters; ZipFile: JZipFile; SourceFile: JFile; |
As you can see this is what we need to create Zip files. With the help of a JZipFile instance (ZipFile) we can create Zip files and set Zip parameters like compression method & level, and encryption method. Furthermore, we may encrypt files with a password.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
// create zip file ZipFile := TJZipFile.JavaClass.init(StringToJString(ZippedFileName), StringToJString(EditPassword.Text).toCharArray); // apply the Zip parameters to Source Files for var I: Byte := 1 to FileCount do begin SourceFile := TJFile.JavaClass.init(StringToJString(FileName(I))); if ZipParameters = nil then begin ZipParameters := TJZipParameters.JavaClass.init; ZipParameters.setCompressionMethod(TJCompressionMethod.JavaClass.DEFLATE); ZipParameters.setCompressionLevel(TJCompressionLevel.JavaClass.MAXIMUM); ZipParameters.setEncryptionMethod(TJEncryptionMethod.JavaClass.ZIP_STANDARD); ZipParameters.setEncryptFiles(EditPassword.Text <> ''); end; ZipFile.addFile(SourceFile, ZipParameters); end; |
Now, learn how to list files in the zip archive here.
1 2 3 4 |
var ZipFile: JZipFile; FileHeaders: JList; FileHeader: JFileHeader; |
- JZipFile & JFileHeader are the main instances in this process.
1 2 3 4 5 6 7 8 9 10 11 |
// get the File Header Data FileHeaders := ZipFile.getFileHeaders; // Get attributes from Header Data for var I: Integer := 0 to FileHeaders.size - 1 do begin FileHeader := TJFileHeader.Wrap(FileHeaders.get(I)); Memo.Lines.Add(JStringToString(FileHeader.getFileName)); Memo.Lines.Add(' Compressed size : ' + IntToStr(FileHeader.getCompressedSize)); Memo.Lines.Add(' Uncompressed size: ' + IntToStr(FileHeader.getUncompressedSize)); end; |
In this function, we are opening a zip file by creating an instance of JZipFile. Then it gets file header data like compressed size and after that, it is printing header data on TMemo component.
Finally, we should see how to extract zip files. We just need a JZipFile instance to open zip files and extract them. You can utilize the extractAll function.
1 |
ZipFile.extractAll(StringToJString(TPath.GetDocumentsPath)); |
Great! We have learned the essential features of the Zip for Android library.
Like what you see? You can get Zip for Android and over 100 other fantastic WinSoft components with our Enterprise Component Pack. For a limited time, when you purchase RAD Studio Enterprise or Architect Edition at special Upgrade Pricing, you will also get this package of third-party software worth over $13,000, including the full WinSoft Component Library, at NO EXTRA COST! Step up to RAD Studio 10.4 today!
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition
