Java提取 .cab 文件

huangapple go评论80阅读模式
英文:

Java extract .cab files

问题

我想从一个 .cab 文件中提取文件并保存它们。在其他问题和 GitHub 上都没有找到有用的信息。

目前我可以使用 CAB 解析器遍历所有条目(2 个文本文件),但我找不到一个好的方法来保存它们,并且希望能得到一些提示。

File inputFile = new File(inputPath);
File outputPath = new File(inputFile.getParentFile().getAbsolutePath());

final InputStream is = new FileInputStream(inputFile);
CabParser cabParser = new CabParser(is, inputPath);
Arrays.stream(cabParser.files).forEach(element -> {
    CabFileEntry cabFile = element;
});

非常感谢!

英文:

I want to extract files from a .cab file and save them. I could not find any useful information on other questions and on GitHub there is no documentation.

For now I can iterate through all entries (2 text files) with CAB Parser but I cannot find a good way to save them and would appreciate some hints.

File inputFile = new File(inputPath);
File outputPath = new File(inputFile.getParentFile().getAbsolutePath());

final InputStream is = new FileInputStream(inputFile);
CabParser cabParser = new CabParser(is, inputPath);
Arrays.stream(cabParser.files).forEach(element -> {
    CabFileEntry cabFile = element;
});

Thanks a lot!

答案1

得分: 1

这似乎适用于 simple.cab

final InputStream is = new FileInputStream("/tmp/simple.cab");
CabParser cabParser = new CabParser(is, new File("/tmp/simple/"));
cabParser.extractStream();

但是,它在 VC_RED.cab 上失败了。

CabParser README.md

从通过 LZX 压缩算法压缩的 .cab 文件中提取文件

也许这个库不支持所有可能的压缩算法。

一种选择是使用 cabextract,并使用 Runtime.exec(...) 运行它。

英文:

This seems to work with simple.cab:

final InputStream is = new FileInputStream("/tmp/simple.cab");
CabParser cabParser = new CabParser(is, new File("/tmp/simple/"));
cabParser.extractStream();

However, it fails with VC_RED.cab.

CabParser README.md:
> extract files from within a .cab which are compressed via the LZX compression algorithm

Maybe not all the possible compression algorithms are supported by this library.

One option is to run cabextract with Runtime.exec(...).

huangapple
  • 本文由 发表于 2020年9月22日 00:38:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/63996521.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定