- 首页 > it技术 > >
private String streamToString(InputStream inputStream, String charset) {try {
//转换流,将字节流转字符串,并转换编码
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, charset);
//字符缓冲流
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
//字符串缓冲区
StringBuilder stringBuilder = new StringBuilder();
//
String len = null;
//按行读
while((len=bufferedReader.readLine())!=null){
//追加到字符串缓冲区存放
stringBuilder.append(len);
}
//将字符串返回
return stringBuilder.toString();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
推荐阅读