Switch to full style
Java2 codes,problems ,discussions and solutions are here
Post a reply

Zipping a Folder in java

Tue Nov 11, 2008 12:35 am

In the following example , show to you how to zip a folder in java ;
Here is the code of the program :
Code:
 import java.io.*;
 
import java.util.zip.*;
 public class 
ZipFolderExample
 
{
 public static 
void main(String a[])
  {
  try
     {
     
File myfolder=new File("out");
     
File outFolder=new File("Out.zip");
     
ZipOutputStream out = new ZipOutputStream(new 
BufferedOutputStream(new FileOutputStream(outFolder)));
     
BufferedInputStream in null;
     
byte[] data    = new byte[1000];
     
String files[] = myfolder.list();
     for (
int i=0i<files.lengthi++)
      {
      
in = new BufferedInputStream(new FileInputStream
(myfolder.getPath() + "/" files[i]), 1000);                  
out.putNextEntry(new ZipEntry(files[i])); 
      
int count;
      while((
count in.read(data,0,1000)) != -1)
      {
           
out.write(data0count);
          }
      
out.closeEntry();
      }
      
out.flush();
      
out.close();
      }
      catch(
Exception e)
         {
              
e.printStackTrace();
          } 
     }
  }  




Post a reply
  Related Posts  to : Zipping a Folder in java
 java code for listing folder contents from remote folder     -  
 create folder in asp.net     -  
 copy folder     -  
 Get all files in folder     -  
 get Folder path and size     -  
 check folder content using asp     -  
 check existence of file or folder in asp     -  
 print all files names in folder     -  
 Adding watermark to all images in a folder     -  
 file exists in upper level folder link     -  

Topic Tags

Java Files and I/O