public static void zipDirectory(File dir,File zipfile) throws IOException, IllegalArgumentException {
  String[] entries=dir.list();
  byte[] buffer=new byte[4096];
  int bytesRead;
  ZipOutputStream out=new ZipOutputStream(new FileOutputStream(zipfile));
  for (int i=0; i < entries.length; i++) {
    File f=new File(dir,entries[i]);
    if (f.isDirectory())     continue;
    FileInputStream in=new FileInputStream(f);
    ZipEntry entry=new ZipEntry(f.getPath());
    out.putNextEntry(entry);
    while ((bytesRead=in.read(buffer)) != -1)     out.write(buffer,0,bytesRead);
    in.close();
  }
  out.close();
}

public static void zipDirectory ( File dir , File zipfile ) throws IOException , IllegalArgumentException { String [ ] entries = dir . list ( ) ; byte [ ] buffer = new byte [ 4096 ] ; int bytesRead ; ZipOutputStream out = new ZipOutputStream ( new FileOutputStream ( zipfile ) ) ; for ( int i = 0 ; i < entries . length ; i ++ ) { File f = new File ( dir , entries [ i ] ) ; if ( f . isDirectory ( ) ) continue ; FileInputStream in = new FileInputStream ( f ) ; ZipEntry entry = new ZipEntry ( f . getPath ( ) ) ; out . putNextEntry ( entry ) ; while ( ( bytesRead = in . read ( buffer ) ) != - 1 ) out . write ( buffer , 0 , bytesRead ) ; in . close ( ) ; } out . close ( ) ; }
method to save the contents of a directory into a zip file . code found online at : http : / / www . java2s . com / code / java / file - input - output / compressfilesusingthejavazipapi . htm
