4

I want to decompress a 7zip/lzma archive with multiple files & directories in Java. I tried to use the official 7zip SDK, but I failed, as my programming skills are not that advanced for this subject. However I fonud some libraries which make the support in Java easier, speaking of LzmaOutputStream/LzmaInputStream - However I don't know how to use those "streams" to decompress a multi-file archive. I am stuck.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Wolkenjaeger
  • 908
  • 1
  • 10
  • 21
  • Check this out http://stackoverflow.com/questions/3435751/how-to-unzip-a-7zip-archive-in-android/35750229#35750229 – Simon Mar 02 '16 at 14:38

1 Answers1

2

In the example, replace compressed with new File("PATH_TO_FILE"). The example code will yield an output stream, I suppose the LzmaOutputStream or the library has appropriate methods for converting the stream to binary or string.

By default Lzma is only a compression algorithm, not a file archiver like tar or zip. (Note: The 7-Zip program is a file archiver, but the library you linked to does not support file traversal and unpacking.

I would suggest using a well-supporter compression algorithm like Zip or gz. If you must use lzma you could use tar to build a file archive and then compress it with lzma. Or use zip with zero compression.

Here is a java TAR library.

matiasf
  • 1,098
  • 1
  • 9
  • 17
  • Thank you for the information. Switching over to another library is not possible, as the 7zip files are provided and the format can not be changed (sad but true). I also can't find any specification to the 7zip archive, which is odd - as there are already some applications available which do support 7zip, but are not opensource. – Wolkenjaeger Aug 13 '10 at 06:35