国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

java - inputstream轉(zhuǎn)為byte數(shù)組 數(shù)組越界
巴扎黑
巴扎黑 2017-05-17 10:03:02
0
2
925

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)路上都是這種處理方式 寫死有越界的可能性

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

巴扎黑
巴扎黑

全部回覆(2)
阿神

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

阿神

雷雷

最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板