6

7zip異なるディレクトリに分割された数百のファイルを含むアーカイブがあります。ターゲットは、FTP サーバーからダウンロードして、電話で抽出することです。

私の問題は、7zipSDK に多くが含まれていないことです。7z ファイルの解凍に関する例、チュートリアル、スニペットを探しています。

(解凍Intentは二次的なオプションにすぎません)

4

2 に答える 2

2

ここに行きます

LZMA SDK は生データをエンコード/デコードするためのエンコーダーとデコーダーを提供するだけですが、7z アーカイブは複数のファイルを格納するための複雑な形式です。

于 2012-12-24T08:02:16.123 に答える
1

魅力のように機能する代替手段を提供するこのページを見つけました。追加するだけです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 です。それ以外は本当に使いやすいです。

于 2016-03-02T14:37:28.230 に答える