java解压zip文件的代码

/**
  * 解压zip格式的压缩包
  *
  * @param filePath
  *            压缩文件路径
  * @param outPath
  *            输出路径
  * @return 解压成功或失败标志
  */
 public static Boolean unZip(String filePath, String outPath) {
  String unzipfile = inPath; // 解压缩的文件名
  try {
   ZipInputStream zin = new ZipInputStream(new FileInputStream(
     unzipfile));
   ZipEntry entry;
   // 创建文件夹
   while ((entry = zin.getNextEntry()) != null) {
    if (entry.isDirectory()) {
     File directory = new File(outPath, entry.getName());
     if (!directory.exists()) {
      if (!directory.mkdirs()) {
       System.exit(0);
      }
     }
     zin.closeEntry();
    } else {
     File myFile = new File(entry.getName());
     FileOutputStream fout = new FileOutputStream(outPath
       + myFile.getPath());
     DataOutputStream dout = new DataOutputStream(fout);
     byte[] b = new byte[1024];
     int len = 0;
     while ((len = zin.read(b)) != -1) {
      dout.write(b, 0, len);
     }
     dout.close();
     fout.close();
     zin.closeEntry();
    }
   }
   return true;
  } catch (IOException e) {
   e.printStackTrace();
   return false;
  }
 }

相关文章:

  • 2021-11-07
  • 2021-07-17
  • 2021-12-22
  • 2022-01-22
  • 2021-12-26
  • 2021-12-30
  • 2021-07-02
  • 2021-11-30
猜你喜欢
  • 2022-02-07
  • 2022-12-23
  • 2021-09-22
  • 2022-02-07
  • 2022-02-07
  • 2022-02-17
  • 2022-12-23
相关资源
相似解决方案