/** * * @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; }
原文地址:https://www.cnblogs.com/lxh520/p/9004120.html
时间: 2024-10-25 11:44:13