是什么导致ZipFile原生崩溃?

时间:2019-01-29 06:39:44

标签: android zipfile

我遇到了本机崩溃,如下所示:

enter image description here

enter image description here

似乎是zipfile本机崩溃,我不知道为什么会这样。使用ZipFile的代码如下

    private static boolean doUnzip(String zipPath, String outputDirectory, String onlyUnzipFile) {
    ZipFile zipFile = null;
    try {
        zipFile = new ZipFile(zipPath);
        Enumeration<? extends ZipEntry> zipList = zipFile.entries();
        ZipEntry ze = null;
        byte[] buffer = new byte[BUFFER_SIZE];

        while (zipList.hasMoreElements()) {
            ze = zipList.nextElement();

            if (ze.isDirectory()) {
                continue;
            }

            String name = ze.getName();
            if (name != null && name.indexOf("\\") != -1) {
                name = name.replaceAll("\\\\", File.separator);
            }
            String filePath = outputDirectory + File.separator + name;

            if ((!TextUtils.isEmpty(onlyUnzipFile))
                    && (filePath.indexOf(onlyUnzipFile) == -1)) {
                continue;
            }
            File file = createFileIfNotExists(filePath);

            OutputStream os = new BufferedOutputStream(new FileOutputStream(file));
            InputStream is = new BufferedInputStream(zipFile.getInputStream(ze));

            int count = 0;
            while ((count = is.read(buffer, 0, BUFFER_SIZE)) != -1) {
                os.write(buffer, 0, count);
            }
            os.flush();

            is.close();
            os.close();

        }

    } catch (FileNotFoundException e) {
        return false;
    } catch (Throwable e) {
        e.printStackTrace();
        return false;
    } finally {
        if(zipFile != null) {
            try {
                zipFile.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    return true;
}

以前有人遇到过这种崩溃吗?我用谷歌搜索,但找不到很多有用的材料。看来这是一种罕见的情况。

0 个答案:

没有答案