android 解析zip文件

private void readZipFile(String file){
        ZipFile zf = null;
        try {
            zf = new ZipFile(file);
            InputStream in = new BufferedInputStream(new FileInputStream(file));
            ZipInputStream zin = new ZipInputStream(in);
            ZipEntry ze;
            while ((ze = zin.getNextEntry()) != null) {
                if (ze.isDirectory()) {
                    //Do nothing
                } else {
                    if (ze.getName().contains("payload_properties.txt")) {
                        BufferedReader br = new BufferedReader(
                        new InputStreamReader(zf.getInputStream(ze)));
                        String line;
                        while ((line = br.readLine()) != null) {
                            headerKeyValuePairs[i] = line;
                            i++;
                        }
                        br.close();
                    }
                    if (ze.getName().contains("metadata")) {
                        BufferedReader br = new BufferedReader(
                        new InputStreamReader(zf.getInputStream(ze)));
                        String line;
                        while ((line = br.readLine()) != null) {
                            updateTemp1[j] = line;
                            j++;
                        }
                        br.close();
                    }
                }
            }
            zin.closeEntry();
            readSize();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章