package com.chen.util; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; public class DecompressionZip { /** * 解压zip文件 * @param zipFileName * @param inputFile */ public static void zip(String zipFileName, String inputFile) { // TODO Auto-generated method stub long startTime = System.currentTimeMillis(); try { ZipInputStream Zin = new ZipInputStream(new FileInputStream( zipFileName));// 输入源zip路径 BufferedInputStream Bin = new BufferedInputStream(Zin); String Parent = inputFile; // 输出路径(文件夹目录) File Fout = null; ZipEntry entry; try { while ((entry = Zin.getNextEntry()) != null && !entry.isDirectory()) { Fout = new File(Parent, entry.getName()); if (!Fout.exists()) { (new File(Fout.getParent())).mkdirs(); } FileOutputStream out = new FileOutputStream(Fout); BufferedOutputStream Bout = new BufferedOutputStream(out); int b; while ((b = Bin.read()) != -1) { Bout.write(b); } Bout.close(); out.close(); System.out.println(Fout + "解压成功"); } Bin.close(); Zin.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } long endTime = System.currentTimeMillis(); System.out.println("耗费时间: " + (endTime - startTime) + " ms"); } }
最近下载更多