英文:
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(...).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论