将流转化为字符串

来源:互联网 发布:java的简单数据类型 编辑:程序博客网 时间:2024/06/02 23:41


将流作为参数传入即可。  直接转化为字符串。

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