Import Java.io.bufferedinputstream;import Java.io.bufferedoutputstream;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.zipexception;import Java.util.zip.zipfile;public class ZipUtil { public static void Unzip (String zipfile) {//To unzip the file path to the filename "= ' new file ' (ZipFile); if (!file.exists () | |!file.isfile ()) {return; }//File current folder String BasePath = File.getparent (); Buffer size int buffersize = 1024; int count = 0; Buffer byte[] buffer = new Byte[buffersize]; try {//zip file ZipFile zfile = new ZipFile (file); Get all the elements in the zip package enumeration<zipentry> zips = (enumeration<zipentry>) zfile.entries (); Traverse all elements in the ZIP package while (zips.hasmoreelements ()) {//Get file ZipentRy entry = Zips.nextelement (); File name String name = Entry.getname (); The full path of the extracted file is String FilePath = basepath + file.separator + name; Handle the zip file containing the folder if (Entry.isdirectory ()) {System.out.println ("isdirectory"); File path = new file (FilePath); if (!path.exists ()) {Path.mkdir (); } continue; }//Get compressed file input stream InputStream in = Zfile.getinputstream (entry); Buffered input stream Bufferedinputstream bis = new Bufferedinputstream (in); Buffered input stream Bufferedoutputstream bos = new Bufferedoutputstream (new FileOutputStream (FilePath)); Reads bytes from the input stream and writes to the output stream while (count = bis.read (buffer, 0, buffersize))! =-1) {Bos.wri Te (buffer, 0, count); } Release resources Bos.flush (); Bos.close (); Bos.close (); }//Close file Zfile.close (); } catch (Zipexception e) {} catch (IOException e) {}} public static Voi D main (string[] args) {ziputil.unzip ("E:\\pics.zip"); }}
Java Unzip zip file