/**
* 把流转化为字符串String类型的工具类
*
* @author xiaoke
*
*/
public class StreamUtil {
public static String stream2String(InputStream is) throws IOException {
if (is != null) {
// ByteArrayOutputStream好处:边读,边缓冲数据
// 可以捕获内存缓冲区的数据,转换成字节数组。
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int temp = -1;
while ((temp = is.read(buffer)) != -1) {
baos.write(buffer, 0, temp);
}
is.close();
baos.close();
return baos.toString();
}
return null;
}
}