Decompress local zip files in android/java
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 the local compressed file **/public class UnZipLocal {/***** @ param zipFileName * path of the compressed file + file name + suffix * @ param outputDirectory * decompress the package. * @ throws IOException */@ SuppressWar Nings ("unchecked") public static void unzip (String zipFileName, String outputDirectory) throws IOException {ZipFile zipFile = null; try {zipFile = new ZipFile (zipFileName); Enumeration e = zipFile. entries (); ZipEntry zipEntry = null; File dest = new File (outputDirectory); dest. 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, name. 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 + entryName. substring (0, index); df. mkdirs ();} index = entryName. lastIndexOf ("/"); if (index! =-1) {File df = new File (outputDirectory + File. separator + entryName. substring (0, index); df. 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 ())! =-1) {out. write (by, 0, c);} out. flush () ;}} catch (IOException ex) {ex. printStackTrace (); throw new IOException ("decompression failed:" + ex. toString ();} finally {if (in! = Null) {try {in. close ();} catch (IOException ex) {}} if (out! = Null) {try {out. close () ;}catch (IOException ex) {}}} catch (IOException ex) {ex. printStackTrace (); throw new IOException ("decompression failed:" + ex. toString ();} finally {if (zipFile! = Null) {try {zipFile. close () ;}catch (IOException ex ){}}}}}