日期:2014-05-20  浏览次数:20790 次

java里面InputStream类型转换成String类型怎么实现?
rt,谢谢。

------解决方案--------------------
无语...这也能转?
------解决方案--------------------
InputStream是一个流类型阿,你可以读出来放到bytes[]数组中,然后new String(bytes[])就可以了阿
------解决方案--------------------
InputStream.toString()
哈哈
------解决方案--------------------
把InputStream里面的数据先读出来放到byte数组里,然后再转成String
------解决方案--------------------
InputStream是输入流,可以直接打印出来,也可以放在数组中,对数组进行转换。
------解决方案--------------------
read_string或者试试这个方法
------解决方案--------------------
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();
}
------解决方案--------------------
LS的好像可行
------解决方案--------------------
用下面这个吧

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();
}
------解决方案--------------------
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();
}
都行得通
哈哈
------解决方案--------------------
楼主给点分吧