13

を使用して Android アセット フォルダーにある ZIP ファイルからファイルZipInputStreamを読み取っていgetNextEntry()ます。

ZIPファイルをSDカードにコピーすれば読み込みは速いのですが、アセットファイルでのZipFile.getEntry使い方が思いつきませんでした!ZipFile

アセットフォルダーの ZIP にすばやくアクセスする方法はありますか? それとも、ZIP を SD カードにコピーする必要がありますか?

(ところで、なぜ私がこれを行っているのか不思議に思う人がいるかもしれませんが、アプリは 50 MB を超えるため、Play ストアで取得するには拡張 APK を使用する必要があります。ただし、このアプリはAmazon App Store、これには別のバージョンを使用する必要があります。Amazon は拡張 APK を当然サポートしていないためです... 2 つの異なる場所にある ZIP ファイルにアクセスするのが簡単な方法だと思っていましたが、残念ながら.. .)

4

3 に答える 3

4

これは私のために働く:

private void loadzip(String folder, InputStream inputStream) throws IOException
{
    ZipInputStream zipIs = new ZipInputStream(inputStream); 
    ZipEntry ze = null;

            while ((ze = zipIs.getNextEntry()) != null) {

                FileOutputStream fout = new FileOutputStream(folder +"/"+ ze.getName());

                byte[] buffer = new byte[1024];
                int length = 0;

                while ((length = zipIs.read(buffer))>0) {
                fout.write(buffer, 0, length);
                }
                zipIs.closeEntry();
                fout.close();
            }
            zipIs.close();
}
于 2014-07-01T10:23:49.150 に答える
2

非圧縮ファイルをアセットに直接保存できます (つまり、zip を assets/ フォルダーに解凍します)。このようにして、ファイルに直接アクセスでき、APK をビルドするときに圧縮されます。

于 2014-04-11T07:27:26.537 に答える
1

次の方法で ZipInputStream を作成できます。

ZipInputStream zipIs = new ZipInputStream(context.getResources().openRawResource(your.package.com.R.raw.filename)); 
ZipEntry ze = null;

        while ((ze = zipIs.getNextEntry()) != null) {

            FileOutputStream fout = new FileOutputStream(FOLDER_NAME +"/"+ ze.getName());

            byte[] buffer = new byte[1024];
            int length = 0;

            while ((length = zipIs.read(buffer))>0) {
            fout.write(buffer, 0, length);
            }
            zipIs .closeEntry();
            fout.close();
        }
        zipIs .close();
于 2012-07-23T15:00:44.953 に答える