小编Jac*_*ack的帖子

Android:更快的方式来读/写ZipInputStream?

我目前正在编写一个应用程序,它在我的资源文件夹中读取一个zip文件,其中包含一堆图像.我正在使用ZipInputStreamAPI来读取内容,然后将每个文件写入my:Environment.getExternalStorageDirectory()目录.我有一切正常,但第一次运行应用程序将图像写入存储目录是不可思议的慢.将我的图像写入光盘大约需要5分钟.我的代码看起来像这样:

ZipEntry ze = null;
ZipInputStream zin = new ZipInputStream(getAssets().open("myFile.zip"));
String location = getExternalStorageDirectory().getAbsolutePath() + "/test/images/";

    //Loop through the zip file
    while ((ze = zin.getNextEntry()) != null) {
         File f = new File(location + ze.getName());
          //Doesn't exist? Create to avoid FileNotFoundException
          if(f.exists()) {
             f.createNewFile();
          }
          FileOutputStream fout = new FileOutputStream(f);
          //Read contents and then write to file
          for (c = zin.read(); c != -1; c = zin.read()) {
             fout.write(c);
          }             
    }
    fout.close();
    zin.close();
Run Code Online (Sandbox Code Playgroud)

读取特定条目的内容然后写入它的过程非常慢.我认为这更多的是阅读而不是写作.我已经读过你可以使用byte[]数组缓冲来加速这个过程,但这似乎不起作用!我尝试了这个,但它只读取了部分文件... …

android zipinputstream fileoutputstream

4
推荐指数
2
解决办法
5302
查看次数

标签 统计

android ×1

fileoutputstream ×1

zipinputstream ×1