搭建一个工具类
/**
* 搭建一个输入流环境
* @param inputStream
* @return
* @throws IOException
*/
public static byte[] readInputStream(InputStream inputStream) throws IOException {
byte[] buffer = new byte[1024];
int len = 0;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
// 数据都是在 buffer中存在,读取数据的时候需要在存储中进行获取数据
while((len = inputStream.read(buffer)) != -1) {
bos.write(buffer, 0, len);
}
bos.close();
return bos.toByteArray();
}
调用:
//
// byte[] getData = readInputStream(inputStream);
// inputStream.read(getData);
// String str = new String(getData);
// System.out.println ("打印内容:"+str);