zip包的解压
Posted 误入IT界的农民工
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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(); } }
以上是关于zip包的解压的主要内容,如果未能解决你的问题,请参考以下文章