Java 如何在Android中解压7zip存档?
我有一个Java 如何在Android中解压7zip存档?,java,android,archive,7zip,Java,Android,Archive,7zip,我有一个7zip归档文件,其中包含数百个分为不同目录的文件。目标是从FTP服务器下载,然后在手机上提取 我的问题是7zipSDK没有包含很多内容。我正在寻找有关7z文件解压缩的示例、教程和代码片段 (通过Intent解压只是一个辅助选项)Go: LZMA SDK只提供用于对原始数据进行编码/解码的编码器和解码器,但7z archive是一种用于存储多个文件的复杂格式。我发现它提供了一种类似魅力的替代方案。您只需添加compile'org.apache.commons:commons compre
7zip
归档文件,其中包含数百个分为不同目录的文件。目标是从FTP服务器下载,然后在手机上提取
我的问题是7zip
SDK没有包含很多内容。我正在寻找有关7z文件解压缩的示例、教程和代码片段
(通过Intent
解压只是一个辅助选项)Go:
LZMA SDK只提供用于对原始数据进行编码/解码的编码器和解码器,但7z archive是一种用于存储多个文件的复杂格式。我发现它提供了一种类似魅力的替代方案。您只需添加compile'org.apache.commons:commons compress:1.8'
创建gradle脚本并使用所需的功能。对于这个问题,我做了以下工作:
AssetManager am = getAssets();
InputStream inputStream = null;
try {
inputStream = am.open("a7ZipedFile.7z");
File file1 = createFileFromInputStream(inputStream);
} catch (IOException e) {
e.printStackTrace();
}
SevenZFile sevenZFile = null;
try{
File f = new File(this.getFilesDir(), "a7ZipedFile.7z");
OutputStream outputStream = new FileOutputStream(f);
byte buffer[] = new byte[1024];
int length = 0;
while((length=inputStream.read(buffer)) > 0) {
outputStream.write(buffer,0,length);
}
try {
sevenZFile = new SevenZFile(f);
SevenZArchiveEntry entry = sevenZFile.getNextEntry();
while (entry != null) {
System.out.println(entry.getName());
FileOutputStream out = openFileOutput(entry.getName(), Context.MODE_PRIVATE);
byte[] content = new byte[(int) entry.getSize()];
sevenZFile.read(content, 0, content.length);
out.write(content);
out.close();
entry = sevenZFile.getNextEntry();
}
sevenZFile.close();
outputStream.close();
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}catch (IOException e) {
//Logging exception
e.printStackTrace();
}
对于导入的库,唯一的回退量约为200k。除此之外,它真的很容易使用。页面底部有一个7-Zip教程列表。谢谢您的回答,但是7zip页面上的链接非常旧,我无法使用。我把这个问题分成了另一个问题:您可能想看看AndroXPlorerV.3。它支持多种文件格式,包括7z。您是否尝试过此解决方案->?它似乎也需要NDK。@出现错误时,它不需要NDK