I won’t say much nonsense, I’ll post the key code to you. The specific code is 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 Created: September 25, 2016 at 11:06:46 am * @version 1.0 * @parameter * @since September 25, 2016 at 11:06:46 am* @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 find the file File file = new File(fileAddress); ZipFile zipFile = null; try { zipFile = new ZipFile(file,"GBK"); //Set the encoding format} catch (IOException exception) { exception.printStackTrace(); System.out.println("The decompressed 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();//Delete the compressed package after decompression}Okay, the code ends here. The above is the key code for Java decompression zip files introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!