首页 > 解决方案 > Assets Manager 在 Android 5.1 上找不到文件

问题描述

我正在编写提取我放置在 apk 资产文件夹中的 zip 文件的函数。该功能在 android 4.4 和 android 8.0 上运行良好。但它在 android 5.1 上返回错误“找不到文件”。我在资产文件夹中的 zip 文件大小超过 1GB。

以下是我提取zip的代码:

@Override
    protected Long doInBackground(Void... voids) {
        String filename = "apk.zip";
        try {
            String[] listAssets = bb.list("");
            int countProgress = 0;
            for(String s : listAssets){
                if(s.equalsIgnoreCase(filename)){
                    filename = s;
                }
            }
            ZipInputStream zipInputStream = new ZipInputStream(bb.open(filename));
            BufferedOutputStream dest = null;
            long inputFileSize = getFileSize(filename);
            while (true) {
                ZipEntry entry = zipInputStream.getNextEntry();
                if (entry == null) {
                    zipInputStream.close();
                    mThread = null;
                    break;
                }
                File file = new File(new StringBuilder(String.valueOf(extractdir)).append(entry.getName()).toString());
                if (!entry.isDirectory()) {
                    BufferedOutputStream dest2;
                    try {
                        byte[] data = new byte[8192];
                        FileOutputStream fileOut = new FileOutputStream(file);
                        long stepIncrease = inputFileSize/100;
                        long countStep = 0;
                        dest2 = new BufferedOutputStream(fileOut, 8192);
                        while (true) {
                            if(countStep == stepIncrease) {
                                countProgress++;
                                publishProgress(countProgress);
                                countStep = 0;
                            }
                            int count = zipInputStream.read(data, 0, 8192);
                            if (count == -1) {
                                break;
                            }
                            countStep++;
                            dest2.write(data, 0, count);
                        }
                        dest2.flush();
                        dest2.close();
                        dest = dest2;
                    } catch (Exception e2) {
                        e2.printStackTrace();
                        dest2 = dest;
                    }
                } else if (!file.exists()) {
                    file.mkdirs();
                }
            }
        } catch (Exception e22) {
           e22.printStackTrace();
        }
        return per;
    }

标签: android

解决方案


推荐阅读