解压.7z格式压缩文件,Java

心已赠人 2024-04-08 10:26 142阅读 0赞

解压读写.7z格式的压缩文件,Java

需要先在pom.xml里面添加引用:

  1. <dependency>
  2. <groupId>org.apache.commons</groupId>
  3. <artifactId>commons-compress</artifactId>
  4. <version>1.21</version>
  5. </dependency>
  6. <dependency>
  7. <groupId>org.tukaani</groupId>
  8. <artifactId>xz</artifactId>
  9. <version>1.9</version>
  10. </dependency>

Java代码:

  1. /**
  2. * @param file 原始的.7z文件
  3. * @throws Exception
  4. */
  5. private void unzip7Z(File file) throws Exception {
  6. SevenZFile zFile = new SevenZFile(file);
  7. SevenZArchiveEntry entry;
  8. while ((entry = zFile.getNextEntry()) != null) {
  9. String name = entry.getName();
  10. System.out.println("文件:" + name);
  11. InputStream is = zFile.getInputStream(entry);
  12. BufferedInputStream bis = new BufferedInputStream(is);
  13. //这里开始,从.7z文件中读取其中一个压缩文件就变成常规的写文件操作
  14. //...
  15. }

发表评论

表情:
评论列表 (有 0 条评论,142人围观)

还没有评论,来说两句吧...

相关阅读