2010-08-08 88 views
6

我有一个7zip存档,其中包含几百个文件分成不同的目录。目标是从FTP服务器下载它,然后在手机上提取它。如何在Android中解压7zip存档?

我的问题是,7zip SDK不包含很多。我正在寻找关于7z文件解压缩的示例,教程和片段。

(经由Intent减压只是一个辅助选择)

+0

7-Zip教程列表位于this page的底部。 – gregS 2010-08-09 12:43:33

+0

感谢您的回答,但7zip页面上的链接相当陈旧,不适用于我。我把这个问题分为另一个:http://stackoverflow.com/questions/3469904/ – Wolkenjaeger 2010-08-12 16:33:03

+0

你可能想看看AndroXplorer v.3。它支持许多文件格式,包括7z。 – Yongki 2011-03-06 07:04:42

回答

2

转到here

LZMA SDK只是提供了一种用于编码/编码器和解码器中的原始数据进行解码,但7Z归档文件是用于存储一个复杂的格式多个文件。

-1

我发现这个page,提供了一个替代品,就像一个魅力。您只需将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。除此之外,它非常易于使用。