首页
IT
登录
6mi
u
盘
搜
搜 索
IT
【HttpUrlConnection】自定义StreamToString--流转换成字符串(1.1)
【HttpUrlConnection】自定义StreamToString--流转换成字符串(1.1)
xiaoxiao
2022-06-23
16
public
class
StringUtils
{
public
static
String
StreamToString
(
InputStream
in
)
throws
IOException
{
//定义一个内存输出流
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
();
//读取流
byte
[]
buf
=
new
byte
[
1024
];
int
len
=-
1
;
while
((
len
=
in
.
read
(
buf
))!=-
1
){
baos
.
write
(
buf
,
0
,
len
);
}
//将流转换成字符串
String
content
=
new
String
(
baos
.
toString
());
return
content
;
}
}
转载请注明原文地址: https://ju.6miu.com/read-1123357.html
专利
最新回复
(
0
)