Package Com.lapel.activity.html;import Java.io.file;import Java.io.fileoutputstream;import java.io.IOException; Import Java.io.inputstream;import java.util.enumeration;import Java.util.zip.zipentry;import java.util.zip.ZipFile /** * * @author ding Unzip local compressed file * */public class Unziplocal {/** * * @param zipfilename * Compressed file path + filename + suffix * @param outputdirectory * After decompression path * @throws IOException */@SuppressWarnings ("unchecked") public static void unzip (String zipfilename, String outputdirectory) throws IOException {ZipFile ZipFile = null;try {zipfile = new ZipFile (ZipFile Name); Enumeration E = Zipfile.entries (); ZipEntry zipentry = null; File Dest = new file (outputdirectory);d est.mkdirs (); while (E.hasmoreelements ()) {ZipEntry = (zipentry) e.nextelement (); String entryName = Zipentry.getname (); InputStream in = null; FileOutputStream out = null;try {if (Zipentry.isdirectory ()) {String name = Zipentry.getname (); name = name.substring (0, NA Me.length ()-1); File F = new file (outputdiRectory + file.separator + name); F.mkdirs ();} else {int index = entryname.lastindexof ("\ \"), if (Index! =-1) {File DF = new file (outputdirectory + file.separator + entr Yname.substring (0, index));d f.mkdirs ();} index = Entryname.lastindexof ("/"); if (Index! =-1) {File DF = new file (outputdirectory + file.separator + entryname.subst Ring (0, index));d f.mkdirs ();} File F = new file (outputdirectory + file.separator + zipentry.getname ());//F.createnewfile (); in = Zipfile.getinputstream (zipentry); out = new FileOutputStream (f); int. c;byte[] by = new Byte[1024];while ((c = In.read (by))! =-1) {Out.write (by, 0 , c);} Out.flush ();}} catch (IOException ex) {ex.printstacktrace (); throw new IOException ("Decompression failed:" + ex.tostring ());} finally {if (in = null) {TR y {in.close ();} catch (IOException ex) {}}if (out! = null) {try {out.close ();} catch (IOException ex) {}}}} catch (Ioexce Ption ex) {ex.printstacktrace (); throw new IOException ("Decompression failed:" + ex.tostring ())} finally {if (ZipFile! = null) {try {ZIPFI Le.close ();} catch (IOException ex) {}}}}
Unzip the local zip archive