久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術(shù)文章
文章詳情頁

java - inputstream轉(zhuǎn)為byte數(shù)組 數(shù)組越界

瀏覽:90日期:2023-12-09 10:37:15

問題描述

public static byte[] readInputStream(InputStream inStream) throws Exception {

try {ByteArrayOutputStream outStream = new ByteArrayOutputStream();byte[] buffer = new byte[1024];int len = 0;while ((len = inStream.read(buffer)) != -1) { outStream.write(buffer, 0, len);}inStream.close();return outStream.toByteArray(); }catch (Exception e){e.printStackTrace();throw new Exception(e); }

}

網(wǎng)上都是這種處理方式 寫死有越界的可能性

不知道有沒有其他的處理方式

問題解答

回答1:

最好的方法是用Apache commons IO的IOUtils.toByteArray(inputStream),一行代碼解決。

回答2:

int count = 0;while (count == 0) { count = inStream.available();}byte[] b = new byte[count];inStream.read(b);return b;

標(biāo)簽: java
相關(guān)文章:
主站蜘蛛池模板: 桓台县| 苍山县| 秭归县| 芦山县| 平安县| 嘉兴市| 留坝县| 陵川县| 虎林市| 盖州市| 巴林左旗| 深州市| 松江区| 柳江县| 太湖县| 漳平市| 阆中市| 巴马| 通许县| 武穴市| 马公市| 惠水县| 彰化市| 龙州县| 彩票| 张家港市| 溧阳市| 三原县| 吉安县| 罗源县| 西藏| 洪泽县| 铁岭市| 松江区| 南丹县| 合水县| 蒙阴县| 卢湾区| 新安县| 大港区| 儋州市|