java inputStream用一次后报错了,我想使用同一个inputStream
1条回答 默认 最新
关注
private static byte[] cloneInputStream(InputStream input) { try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len; while ((len = input.read(buffer)) > -1) { baos.write(buffer, 0, len); } baos.flush(); baos.close() input.close() return baos.toByteArray(); } catch (IOException e) { e.printStackTrace(); return null; } } byte[] bytes = cloneInputStream(inputStream); InputStream inputStream1 = new ByteArrayInputStream(bytes); InputStream inputStream2 = new ByteArrayInputStream(bytes);
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用
悬赏问题
- ¥20 NX二次开发TKLTOOS加载不出来
- ¥15 Intprt在跨语言调用出现问题
- ¥15 诚意满满、携手共进、请多关照
- ¥15 ubuntu下git下来的langchainchatchat没有config目录怎么办(语言-python)
- ¥15 时间序列异常检测(python)
- ¥15 anaconda navigator无法选择python版本
- ¥15 DS1302时钟显示不稳定是怎么回事
- ¥15 做一个简单的bp500元贵吗?
- ¥15 为什么点击加入购物车跳转页面应用程序找不到对应的资源该怎么修改
- ¥15 ANSYS自动化仿真数据