zip - How to Zip your File using Java - Free Source Code

How to Zip your File using Java – Free Source Code

Posted on

zip - How to Zip your File using Java - Free Source Code

In the present day, I’ll train you tips on how to create a program that can zip your file utilizing Java. Everyone knows that zip is a well-liked compression format that additionally incorporates a number of information which were compressed into the ZIP format.

So, now let’s begin this tutorial!

1. Open Notepad. Encode any information in there and reserve it to the identical folder along with your java program and named it as READ FIRST.txt (Notice: you possibly can identify your textual content file in any identify that you really want).

2. Open JCreator or NetBeans and make a java program with a file identify of zipFile.java.

3. Import java.io package deal. Therefore we are going to use an enter/output in creating information. Import additionally java.util.zip package deal to entry the zip class from this utilities.

4. In your predominant, initialize the information.txt that you’ve created some time in the past for this file. This READ FIRTS.txt file is the file that we’ll going to find. Initialize additionally the identify of the zip file after compression. Right here I used createdZipFile.zip. This can be in your Attempt to Catch technique.

Make a ZipOutputStream for the zipFile variable that you’ve created. It will set off to have an output for zipping. Then the FileInputStream for file variable that can be your enter file.

Initialize the worth of the file measurement and its byte.

Create some time loop that reads information to the top of the file and write it to the zip for the outputstream.

Shut the zip course of after ending the compression.

In your Catch technique, favor to catch IOException then use printStackTrace() technique. It will assist to hint the exception and determine which technique causes the bug.

zip - How to Zip your File using Java - Free Source Code

Hope this helps! 🙂

Go to and like my web page on Fb at: Bermz ISware Solutions