解压缩到内部存储不完全正常工作

时间:2014-12-23 08:34:55

标签: java android

我的文件解压缩了一个文件夹和一个文件,但由于某种原因没有解压缩其余文件。如何解压缩所有zip文件内容?

public void unzip(String filepath, String filename, String unzip_path) throws IOException {
    InputStream is = new FileInputStream(filepath + filename);
    Log.d("1st", filepath + filename);
    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;

            String filename_temp = ze.getName();
            File fmd = new File(unzip_path + filename_temp);
            Log.d("2nd", unzip_path + filename_temp);
            if (!fmd.getParentFile().exists()) {
                fmd.getParentFile().mkdirs();
            }

            FileOutputStream fout = new FileOutputStream(unzip_path + filename_temp);

            while ((count = zis.read(buffer)) != -1) {
                baos.write(buffer, 0, count);
                byte[] bytes = baos.toByteArray();
                fout.write(bytes);
                baos.reset();
            }

            fout.close();
            //}
        }
    } finally {
        zis.close();
    }
}

0 个答案:

没有答案
相关问题