public static void unzip ( InputStream is , File destDir ) throws FileNotFoundException , IOException { BufferedOutputStream dest = null ; ZipInputStream zis = new ZipInputStream ( new BufferedInputStream ( is ) ) ; ZipEntry entry ; while ( ( entry = zis . getNextEntry ( ) ) != null ) { //System.out.println("Extracting: " + entry); if ( entry . isDirectory ( ) ) { // Otherwise, empty directories do not get created ( new File ( destDir , entry . getName ( ) ) ) . mkdirs ( ) ; } else { File f = new File ( destDir , entry . getName ( ) ) ; f . getParentFile ( ) . mkdirs ( ) ; int count ; byte data [ ] = new byte [ BUFFER ] ; // write the files to the disk FileOutputStream fos = new FileOutputStream ( f ) ; dest = new BufferedOutputStream ( fos , BUFFER ) ; while ( ( count = zis . read ( data , 0 , BUFFER ) ) != - 1 ) { dest . write ( data , 0 , count ) ; } dest . flush ( ) ; dest . close ( ) ; } } zis . close ( ) ; }
Unzips the InputStream to the given destination directory .