0x44656E6E79
0x44656E6E79

Reputation: 1063

Java extract .cab files

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!

Upvotes: 0

Views: 903

Answers (1)

haba713
haba713

Reputation: 2677

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(...).

Upvotes: 1

Related Questions