java.util.zip对zip文件解压

//通过构造方法,来创建一个新的ZIP输入流

ZipInputStream in = new ZipInputStream(new FileInputStream("G:/jquery.calendar(source)v1.0.0.zip"));

ZipEntry entry = null;
//循环读取,getNextEntry() 方法是,读取下一个ZIP条目,并且将流定位到该条目上

while((entry = in.getNextEntry()) != null){

  String path = "G:/" + entry.getName();

  File file = new File(path);

  //isDirectory()方法来测试这个抽象的路径是否是一个目录,如果是目录,就创建,不是目录,就进行读写

  if(entry.isDirectory()){

     file.mkdirs();

  }else{

    //进行标准的写入

    FileOutputStream out = new FileOutputStream(file);

    int len;

    byte[] buffer = new byte[1024*1024*2];

    while((len = in.read(buffer)) > 0){

      out.write(buffer,0,len);

    }

        //一定要关闭流

   out.flush();

   out.close();

  }

  in.closeEntry();

  in.close();

}
如果有使用请标明来源:http://www.cnblogs.com/duwenlei/
原文地址:https://www.cnblogs.com/duwenlei/p/3472670.html