当前位置:网站首页 > Java教程 > 正文

java压缩解压教程



/ 解压缩(压缩文件中包含多个文件)可代替上面的方法使用。 * ZipInputStream类 * 当我们需要解压缩多个文件的时候,ZipEntry就无法使用了, * 如果想操作更加复杂的压缩文件,我们就必须使用ZipInputStream类 * */ public static void ZipContraMultiFile(String zippath ,String outzippath){ try { File file = new File(zippath); File outFile = null; ZipFile zipFile = new ZipFile(file); ZipInputStream zipInput = new ZipInputStream(new FileInputStream(file)); ZipEntry entry = null; InputStream input = null; OutputStream output = null; while((entry = zipInput.getNextEntry()) != null){ System.out.println("解压缩" + entry.getName() + "文件"); outFile = new File(outzippath + File.separator + entry.getName()); if(!outFile.getParentFile().exists()){ outFile.getParentFile().mkdir(); } if(!outFile.exists()){ outFile.createNewFile(); } input = zipFile.getInputStream(entry); output = new FileOutputStream(outFile); int temp = 0; while((temp = input.read()) != -1){ output.write(temp); } input.close(); output.close(); } } catch (Exception e) { e.printStackTrace(); } }

  • 上一篇: grpc java教程
  • 下一篇: java自学教程5
  • 版权声明


    相关文章:

  • grpc java教程2025-01-24 11:02:05
  • java scoket 教程2025-01-24 11:02:05
  • java语言案例教程2025-01-24 11:02:05
  • java模板使用教程2025-01-24 11:02:05
  • 微信二次开发java视频教程合集2025-01-24 11:02:05
  • java自学教程52025-01-24 11:02:05
  • java座椅安装教程2025-01-24 11:02:05
  • java自学手册教程2025-01-24 11:02:05
  • java455集教程2025-01-24 11:02:05
  • java模块教程2025-01-24 11:02:05