java里面InputStream类型转换成String类型怎么实现?

llcnllcn 2007-05-16 12:37:59
rt,谢谢。
...全文
9616 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
wddlqd 2007-05-16
  • 打赏
  • 举报
回复
把InputStream里面的数据先读出来放到byte数组里,然后再转成String
steven_cheng 2007-05-16
  • 打赏
  • 举报
回复
InputStream.toString()
哈哈
For_suzhen 2007-05-16
  • 打赏
  • 举报
回复
InputStream是一个流类型阿,你可以读出来放到bytes[]数组中,然后new String(bytes[])就可以了阿
li_d_s 2007-05-16
  • 打赏
  • 举报
回复
无语...这也能转?
wangkm 2007-05-16
  • 打赏
  • 举报
回复
楼主给点分吧
Cappuccino_mhc 2007-05-16
  • 打赏
  • 举报
回复
public String inputStream2String (InputStream in) throws IOException {
StringBuffer out = new StringBuffer();
byte[] b = new byte[4096];
for (int n; (n = in.read(b)) != -1;) {
out.append(new String(b, 0, n));
}
return out.toString();
}

public static String inputStream2String(InputStream is) throws IOException{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int i=-1;
while((i=is.read())!=-1){
baos.write(i);
}
return baos.toString();
}
都行得通
哈哈
flyforlove 2007-05-16
  • 打赏
  • 举报
回复
用下面这个吧

public static String inputStream2String(InputStream is) throws IOException{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int i=-1;
while((i=is.read())!=-1){
baos.write(i);
}
return baos.toString();
}
infon 2007-05-16
  • 打赏
  • 举报
回复
LS的好像可行
flyforlove 2007-05-16
  • 打赏
  • 举报
回复
public String inputStream2String (InputStream in) throws IOException {
StringBuffer out = new StringBuffer();
byte[] b = new byte[4096];
for (int n; (n = in.read(b)) != -1;) {
out.append(new String(b, 0, n));
}
return out.toString();
}
For_suzhen 2007-05-16
  • 打赏
  • 举报
回复
read_string或者试试这个方法
murreywang 2007-05-16
  • 打赏
  • 举报
回复
InputStream是输入流,可以直接打印出来,也可以放在数组中,对数组进行转换。

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧