Some days I get stuck on a really simple task. I never had to manipulate compressed archives (zip, 7zip..) on Android and could never imagine it was so hard. The difficulty is not to do it but much in the documentation about how to do it.
By searching I found:
All of this is just old and inapropriate on how to do it the simple way…
After some searches I found about Apache’s commons compress library that supports a lot of archive types: ar, cpio, Unix dump, tar, zip, gzip, XZ, Pack200, bzip2, 7z, arj, lzma, snappy, DEFLATE and Z files.
With the gradle build system, just addcompile 'org.apache.commons:commons-compress:1.8'
Here is a sample of code on how to use this to extract all files of a 7Zip archive:
String myPath = getContentStorage() + "/myArchivePath/";
SevenZFile sevenZFile = new SevenZFile(new File(myPath + "archive.7z"));
SevenZArchiveEntry entry = sevenZFile.getNextEntry();
FileOutputStream out = new FileOutputStream(myPath + entry.getName());
byte content = new byte[(int) entry.getSize()];
sevenZFile.read(content, 0, content.length);
entry = sevenZFile.getNextEntry();
This library is really simple to use and robust. The only downside of it is that it my be too powerfull and too big for a simple project.
I hope you won’t lose time as I did searching for a simple solution!