如何在Android上解压缩更大的拉链?

时间:2016-05-10 14:17:50

标签: android performance unzip zipinputstream

我在我的Android Studio项目中解压缩文件,如this

 InputStream is = ...
 ZipInputStream zis = new ZipInputStream(new BufferedInputStream(is));
 try {
     ZipEntry ze;
     while ((ze = zis.getNextEntry()) != null) {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         byte[] buffer = new byte[1024];
         int count;
         while ((count = zis.read(buffer)) != -1) {
             baos.write(buffer, 0, count);
         }
         String filename = ze.getName();
         byte[] bytes = baos.toByteArray();
         // do something with 'filename' and 'bytes'...
     }
 } finally {
     zis.close();
 }

原始的zip文件大约是。 30 MB大,只包含* .txt文件。其中两个文本文件是> 100 MB,以便我收到此错误消息:

  

E / AndroidRuntime:FATAL EXCEPTION:主程序:com.example.myapp,   PID:15821 java.lang.OutOfMemoryError:无法分配   167083628字节分配33542384个空闲字节和136MB直到OOM         在java.io.ByteArrayOutputStream.expand(ByteArrayOutputStream.java:91)         at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:201)         在com.example.myapp.managers.UnzipManager.decompressZip(UnzipManager.java:104)         在com.example.myapp.managers.UnzipManager。(UnzipManager.java:43)         在com.example.myapp.MyActivity.onCreate(MyActivity.java:103)         在android.app.Activity.performCreate(Activity.java:6272)         在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)         在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2387)         在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2494)         在android.app.ActivityThread.access $ 900(ActivityThread.java:157)         在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1356)         在android.os.Handler.dispatchMessage(Handler.java:102)         在android.os.Looper.loop(Looper.java:148)         在android.app.ActivityThread.main(ActivityThread.java:5551)         at java.lang.reflect.Method.invoke(Native Method)         在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:730)         在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)

如何解压缩这些文件?

0 个答案:

没有答案