将流转化为字符串的方法

来源:互联网 发布:淘宝网 桌子 编辑:程序博客网 时间:2024/04/29 20:21
public class StreamTools {


public static String readStream(InputStream is){

try {

ByteArrayOutputStream baos = new ByteArrayOutputStream();

byte[] buffer = new byte[1024];
int len = -1;
while((len = is.read(buffer)) != -1){
baos.write(buffer, 0, len);
}
is.close();
return new String(baos.toByteArray());
} catch (Exception e) {
return "";
}


}


}
0 0
原创粉丝点击