I was automating the archive process of one of my old computer. While doing that, I wrote an utility which automatically dumped a series of files in a zip file, which was later exported or backedup in a drive.

Below is the source code which adds a file "helloworld.txt' to "helloworld.zip'.


package com.tutorial;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.zip.*;
 * This class creates a zip file.
 * @author JavaGenious.com
public class JavaGeniousZipCreate{

   public static void main(String[] args)  throws Exception  {
           // input file 
       FileInputStream in = new FileInputStream("helloworld.txt");;
       // out put file 
       ZipOutputStream out =new ZipOutputStream(new FileOutputStream("helloworld.zip"));

       out.putNextEntry(new ZipEntry("helloworld.txt")); 

       byte[] b = new byte[1024];

       int count;

       while ((count = in.read(b)) > 0) {

        out.write(b, 0, count);

Enter your email address:

Delivered by FeedBurner

Sandeep Joshi
Mathematics, Technology and Programming are my passion. I am a part of Java Ecosystem and through this blog, I contribute to it. I am here to blog about my interests, views and experiences.
I am on Google+ and Facebook.
I feel proud to be listed as a "National Memory Record Holder" in the Limca Book of Records, 2009 and have attempted for an International Memory record in the Guiness Book of Records. I can remember the value of PI upto 10,000 digits after the decimal (3.1415.....). You can contact me on javagenious.com(At)gmal.com ; I would like to hear from you :)