public static void zipDir( File zipFile, File directoryToZip )
                            throws Exception {
        if ( !directoryToZip.isDirectory() ) {
            throw new IllegalArgumentException( "Directory to zip is not a directory" );
        }
        try {
            ZipOutputStream out = new ZipOutputStream( new FileOutputStream( zipFile ) );
            File parentDir = new File( directoryToZip.toURI().resolve( ".." ) );
            for ( File file : directoryToZip.listFiles() ) {
                zip( parentDir, file, out );
            }
            out.flush();
            out.close();
        } catch ( IOException e ) {
            throw new Exception( e.getMessage() );
        }

    }
public static void zipDir ( File zipFile , File directoryToZip ) throws Exception { if ( ! directoryToZip . isDirectory ( ) ) { throw new IllegalArgumentException ( "Directory to zip is not a directory" ) ; } try { ZipOutputStream out = new ZipOutputStream ( new FileOutputStream ( zipFile ) ) ; File parentDir = new File ( directoryToZip . toURI ( ) . resolve ( ".." ) ) ; for ( File file : directoryToZip . listFiles ( ) ) { zip ( parentDir , file , out ) ; } out . flush ( ) ; out . close ( ) ; } catch ( IOException e ) { throw new Exception ( e . getMessage ( ) ) ; } }
Zips the directory and all of it's sub directories

@param zipFile
the file to write the files into, never <code>null</code>
@param directoryToZip
the directory to zip, never <code>null</code>
@throws Exception
if the zip file could not be created
@throws IllegalArgumentException
if the directoryToZip is not a directory