/night_iv/article/details/7525760?utm_source=blogxgwz5
/yongdaimi/p/12367746.html
在commons-io包中mons.io.IOUtils类的toByteArray(InputStream input)已经有实现了,我们可以参考下思路,完成我们的方法,我们可以用类似下面的代码实现inputStream转化为byte[]数组
public static byte[] readStream(InputStream is) throws Exception{byte[] bytes = new byte[1024];int leng;ByteArrayOutputStream baos = new ByteArrayOutputStream();while((leng=is.read(bytes)) != -1){baos.write(bytes, 0, leng);}return baos.toByteArray();}
字节数组转换成字符串:
String mString = new String(byte);//假设为上面的字节数组