zip包的解压

public static void unzip1(String zipName, String temPath) throws IOException {
		ZipFile zip = new ZipFile(new File(zipName),Charset.forName("UTF-8"));
		String zipName1 = zip.getName().substring(zip.getName().lastIndexOf("\") + 1, zip.getName().lastIndexOf("."));
		System.out.println(zipName1);
		String temp = temPath + "/" + zipName1 + System.currentTimeMillis();
		File filePath = new File(temp);
		if (!filePath.exists()) {
			filePath.mkdirs();
		}
		
		for (Enumeration<ZipEntry> zipEntrys = (Enumeration<ZipEntry>) zip.entries(); zipEntrys.hasMoreElements();) {
			ZipEntry entry = zipEntrys.nextElement();
			String name = entry.getName();
			 System.out.println(name);
			InputStream is = zip.getInputStream(entry);
			String outputPath = (temp + "/" + name).replaceAll("\*", "/");
			//判断文件路径是否存在
			File file = new File(outputPath.substring(0, outputPath.lastIndexOf("/")));
			if (!file.exists()) {
				file.mkdirs();
			}
			
			if (new File(outputPath).isDirectory()) {
				continue;
			}
			
			FileOutputStream os = new FileOutputStream(outputPath);
			byte[] buf = new byte[1024]; 
			int len = 0;
			while((len = is.read(buf)) != -1) {
				os.write(buf, 0, len);
			}
			os.close();
			is.close();
		}
		System.out.println("解压成功。。。。");
	}
	
	public static void main(String[] args) {
		String dir = "E:/test";
		String zipName = "E:/test/zhangsan.zip";
		String tempPath = "E:/zip";
//		unzip(dir, zipName, tempPath);
		File file = new File(zipName);
		try {
//			unZipFiles(file, tempPath);
			
//			unzip1(zipName, tempPath);
			System.out.println(invertOrder(123569));
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

  

原文地址:https://www.cnblogs.com/wangxiaowang/p/7818792.html