public static void createArchive(File directory,File archive){
  ZipOutputStream zos=null;
  FileInputStream fis=null;
  File[] contents=directory.listFiles();
  try {
    zos=new ZipOutputStream(new FileOutputStream(archive));
    for (    File file : contents) {
      if (file.isFile()) {
        zos.putNextEntry(new ZipEntry(file.getName()));
        try {
          fis=new FileInputStream(file);
          int bytes;
          byte[] packet=new byte[COPY_PACKET_SIZE];
          while ((bytes=fis.read(packet,0,COPY_PACKET_SIZE)) != -1)           zos.write(packet,0,bytes);
        }
  finally {
          try {
            if (fis != null)             fis.close();
          }
 catch (          Exception e) {
            LOGGER.log(Level.SEVERE,"Problem closing archive entry stream",e);
          }
          if (zos != null)           zos.closeEntry();
        }
      }
 else {
      }
    }
  }
 catch (  Exception e) {
    LOGGER.log(Level.SEVERE,"Error creating archive",e);
  }
 finally {
    try {
      if (zos != null)       zos.close();
    }
 catch (    Exception e) {
      LOGGER.log(Level.SEVERE,"Problem closing archive stream",e);
    }
  }
}

public static void createArchive ( File directory , File archive ) { ZipOutputStream zos = null ; FileInputStream fis = null ; File [ ] contents = directory . listFiles ( ) ; try { zos = new ZipOutputStream ( new FileOutputStream ( archive ) ) ; for ( File file : contents ) { if ( file . isFile ( ) ) { zos . putNextEntry ( new ZipEntry ( file . getName ( ) ) ) ; try { fis = new FileInputStream ( file ) ; int bytes ; byte [ ] packet = new byte [ COPY_PACKET_SIZE ] ; while ( ( bytes = fis . read ( packet , 0 , COPY_PACKET_SIZE ) ) != - 1 ) zos . write ( packet , 0 , bytes ) ; } finally { try { if ( fis != null ) fis . close ( ) ; } catch ( Exception e ) { LOGGER . log ( Level . SEVERE , "Problem closing archive entry stream" , e ) ; } if ( zos != null ) zos . closeEntry ( ) ; } } else { } } } catch ( Exception e ) { LOGGER . log ( Level . SEVERE , "Error creating archive" , e ) ; } finally { try { if ( zos != null ) zos . close ( ) ; } catch ( Exception e ) { LOGGER . log ( Level . SEVERE , "Problem closing archive stream" , e ) ; } } }
creates a zip archive of the given directory . currently doesn ' t support archiving subdirectories ( only files are added to the archive ) .
