public static void zip ( File zipFile , final File contents ) throws IOException { OutputStream os = new FileOutputStream ( zipFile ) ; final ZipOutputStream zs = new ZipOutputStream ( os ) ; try { preOrderTraversal ( contents , new FileVisitor ( ) { public boolean visit ( File file ) throws IOException { if ( file . isFile ( ) ) { String name = getRelativePath ( file , contents ) ; zs . putNextEntry ( new ZipEntry ( name ) ) ; FileInputStream fs = new FileInputStream ( file ) ; StreamUtil . writeStream ( fs , zs ) ; fs . close ( ) ; zs . closeEntry ( ) ; } return true ; } } ) ; } catch ( IOException e ) { throw e ; } catch ( Exception e ) { throw new UnexpectedException ( e ) ; } zs . close ( ) ; }
Zips the contents of a directory .