Java ZIP文件解压

Java ZIP文件解压 备忘笔记

代码:

Java ZIP文件解压
    private byte[] unZip(byte[] data) {
        byte[] bArr = null;
        try {
            ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(data);
            ZipInputStream zipInputStream = new ZipInputStream(byteArrayInputStream);
            ZipEntry zipEntry = null;

            while ((zipEntry = zipInputStream.getNextEntry()) != null) {
                if (zipEntry.isDirectory()) continue;

                byte[] buffer = new byte[1024];
                int num = -1;
                ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

                while ((num = zipInputStream.read(buffer, 0, buffer.length)) != -1) {
                    outputStream.write(buffer, 0, num);
                }

                bArr = outputStream.toByteArray();
                outputStream.flush();
                outputStream.close();

                if (zipEntry.getName().toUpperCase().equals("GAB_ZIP_INDEX.XML")) { //索引文件
                    String xmlStr = new String(bArr, "utf-8");
                    indexXml = getIndexXml(xmlStr);
                }

                if (zipEntry.getName().toUpperCase().indexOf(".BCP") > 0) { //bcp数据文件
                    String bcpStr = new String(bArr, "utf-8");
                    bcpContent.put(zipEntry.getName(), bcpStr);
                }
            }

            zipInputStream.close();
            byteArrayInputStream.close();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return bArr;
    }
View Code

 

上一篇:对于简单的反扒


下一篇:爬虫入门