Click here to Skip to main content
13,861,149 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


9 bookmarked
Posted 7 Jan 2009
Licenced CPOL

Compressing and Uncompressing Files in Java

, 7 Jan 2009
Rate this:
Please Sign up or sign in to vote.
In this article, I’ll show you how to compress and extract files easily in Java using ziputil.jar.


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.

Compressing Files

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 UncompressedFile

u.addFile(new BinaryFileData("test1.txt",

u.addFile(new BinaryFileData("test2.BUP",

u.addFile(new BinaryFileData("test3.BUP",

u.addFile(new BinaryFileData("test4.BUP",

Now you are ready to compress these files. Call the method ZipFileUtil.compress as shown below: 

byte[] b=ZipFileUtil.compress(u);    

Finally call ZipFileUtil.byteArrayToFile to save the new zip file to your file system.  


Extracting Files

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: 

UncompressedFile u=


  • 7th January, 2009: Article created ( is not explained yet)


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Thilina S Hasantha
Software Developer Mubasher
Sri Lanka Sri Lanka
Skype: thilina84
Yahoo: thilina84
Blog :

You may also be interested in...

Comments and Discussions

GeneralThanks Pin
Rodrigo.Santellan4-Mar-09 2:22
memberRodrigo.Santellan4-Mar-09 2:22 
GeneralMy vote of 2 Pin
kma6920-Jan-09 9:12
memberkma6920-Jan-09 9:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web02 | 2.8.190214.1 | Last Updated 7 Jan 2009
Article Copyright 2009 by Thilina S Hasantha
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid