No more nonsense, to put the key code for everyone, the specific code as follows:
import java.io.File; import java.io.FileOutputStream; import java.io.IOException;
Import Java.io.InputStream;
Import java.util.Enumeration;
Import Org.apache.tools.zip.ZipEntry;
Import Org.apache.tools.zip.ZipFile;
Import Org.springframework.stereotype.Service;
Import org.springframework.transaction.annotation.Transactional; /** * @date Creation Date: September 25, 2016 Morning 11:06:46 * @version 1.0 * @parameter * @since September 25, 2016 morning 11:06:46 * @return * * Public
Class Unzipfiles {//zip file path String fileaddress = "D:\\test.zip";
ZIP file decompression address String unzipaddress = "f:\\unzipfiles\\";
Go to the directory to look for files file = new filename (fileaddress);
ZipFile zipfile = null;
try {zipfile = new ZipFile (file, GBK);//Set encoding format} catch (IOException exception) {exception.printstacktrace ();
System.out.println ("Extract file does not exist!");
} Enumeration E = Zipfile.getentries ();
while (E.hasmoreelements ()) {ZipEntry ZipEntry = (zipentry) e.nextelement (); if (Zipentry.isdirecTory ()) {String name = Zipentry.getname ();
Name = Name.substring (0,name.length ()-1);
File F = new file (unzipaddress + name);
F.mkdirs ();
else {file F = new file (unzipaddress + zipentry.getname ());
F.getparentfile (). Mkdirs ();
F.createnewfile ();
InputStream is = Zipfile.getinputstream (zipentry);
FileOutputStream fos = new FileOutputStream (f);
int length = 0;
Byte[] B = new byte[1024];
while ((Length=is.read (b, 0, 1024))!=-1) {fos.write (b, 0, length);
} is.close ();
Fos.close ();
} if (ZipFile!= null) {zipfile.close (); () File.deleteonexit () ()//after decompression, delete the compressed package}
OK, the code is over, the above is a small set to introduce Java extract zip file key code, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!