In this article, I'll show you how to compress and extract files easily in Java using ziputil.jar.
You don't need any external libraries or configurations except ziputil.jar to test this project. You can download the source from the link at the top of this article. Source code for the project contains source for ziputil.jar and test classes and files to be tested.
Uncompressed file class represents an uncompressed state of a zip file. Before compressing a set of files, you need to create an Uncompressed file as shown below passing the path to create the new zip file.
UncompressedFile u=new UncompressedFile("./testFiles/TEST.ZIP");
Then you can add files which needed to be compressed, to
Now you are ready to compress these files. Call the method
ZipFileUtil.compress as shown below:
ZipFileUtil.byteArrayToFile to save the new zip file to your file system.
To uncompress a file, call the
ZipFileUtil.extract method passing path to the zip file to be extracted and path of the folder to save extracted files as below:
- 7th January, 2009: Article created (ziputil.zip is not explained yet)