为了方便使用,创建一个工具类,写一个静态方法
class StreamToos {
/**
* 将输入流流转化成字符串
* @param is
* @return
*/
public static String readFromNetWork(InputStream is){
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = 0;
while ((len = is.read(buffer)) != -1){
baos.write(buffer,0,len);
}
return baos.toString();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}