zip文件的解压,获取字节流


/**
     * 
     * @param inputStream 输入流
     * @return 返回数据
     */
    private static String decompress(InputStream inputStream) {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ZipInputStream zipInputStream = new ZipInputStream(inputStream);
        String rtn = null;
        try {
            while (zipInputStream.getNextEntry() != null) {
                int size = 0;
                byte[] buffer = new byte[1024];
                while (true) {
                    size = zipInputStream.read(buffer, 0, buffer.length);
                    if (size <= 0) {
                        break;
                    }
                    bos.write(buffer, 0, size);
                }
                bos.flush();
                bos.close();
            }
            zipInputStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                byte[] be = bos.toByteArray();
                rtn = new String(be, "utf-8");
                bos.flush();
                bos.close();
                zipInputStream.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return rtn;
    }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM