public static File extractArchive(File archive,File destination){
  File directory=getUniqueFile(destination,archive.getName());
  ZipFile zipFile=null;
  try {
    prepareDirectory(directory);
    zipFile=new ZipFile(archive);
    Enumeration<? extends ZipEntry> entries=zipFile.entries();
    while (entries.hasMoreElements()) {
      ZipEntry entry=entries.nextElement();
      FileOutputStream fos=null;
      InputStream is=null;
      try {
        is=zipFile.getInputStream(entry);
        fos=new FileOutputStream(new File(directory,entry.getName()));
        int bytes;
        byte[] packet=new byte[COPY_PACKET_SIZE];
        while ((bytes=is.read(packet,0,COPY_PACKET_SIZE)) != -1)         fos.write(packet,0,bytes);
      }
  finally {
        try {
          if (fos != null)           fos.close();
        }
 catch (        Exception e) {
          LOGGER.log(Level.SEVERE,"Problem closing extracted file stream",e);
        }
        try {
          if (is != null)           is.close();
        }
 catch (        Exception e) {
          LOGGER.log(Level.SEVERE,"Problem closing zipentry stream",e);
        }
      }
    }
  }
 catch (  Exception e) {
    LOGGER.log(Level.SEVERE,"Error extracting archive",e);
    return null;
  }
 finally {
    try {
      if (zipFile != null)       zipFile.close();
    }
 catch (    Exception e) {
      LOGGER.log(Level.SEVERE,"Problem closing archive",e);
    }
  }
  return directory;
}

public static File extractArchive ( File archive , File destination ) { File directory = getUniqueFile ( destination , archive . getName ( ) ) ; ZipFile zipFile = null ; try { prepareDirectory ( directory ) ; zipFile = new ZipFile ( archive ) ; Enumeration < ? extends ZipEntry > entries = zipFile . entries ( ) ; while ( entries . hasMoreElements ( ) ) { ZipEntry entry = entries . nextElement ( ) ; FileOutputStream fos = null ; InputStream is = null ; try { is = zipFile . getInputStream ( entry ) ; fos = new FileOutputStream ( new File ( directory , entry . getName ( ) ) ) ; int bytes ; byte [ ] packet = new byte [ COPY_PACKET_SIZE ] ; while ( ( bytes = is . read ( packet , 0 , COPY_PACKET_SIZE ) ) != - 1 ) fos . write ( packet , 0 , bytes ) ; } finally { try { if ( fos != null ) fos . close ( ) ; } catch ( Exception e ) { LOGGER . log ( Level . SEVERE , "Problem closing extracted file stream" , e ) ; } try { if ( is != null ) is . close ( ) ; } catch ( Exception e ) { LOGGER . log ( Level . SEVERE , "Problem closing zipentry stream" , e ) ; } } } } catch ( Exception e ) { LOGGER . log ( Level . SEVERE , "Error extracting archive" , e ) ; return null ; } finally { try { if ( zipFile != null ) zipFile . close ( ) ; } catch ( Exception e ) { LOGGER . log ( Level . SEVERE , "Problem closing archive" , e ) ; } } return directory ; }
extracts given zip archive , returns extracted directory . currently doesn ' t support extracting subdirectories , ( only extracts toplevel files ) .
