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;
    }

猜你喜欢

转载自www.cnblogs.com/lxh520/p/9004120.html