现在的位置: 首页 > 综合 > 正文

java中InputStream & String 的互相转换

2013年09月07日 ⁄ 综合 ⁄ 共 395字 ⁄ 字号 评论关闭

 1 String to InputStream

InputStream String2InputStream(String str)

{

ByteArrayInputStream stream = new ByteArrayInputStream(str.getBytes());

return stream;

}

2 InputStream to String

String inputStream2String (InputStream is)

{

BufferedReader in =new BufferedReader(new InputStreamReader(is));

StringBuffer buffer =new StringBuffer();

String line = "";

while((line = in.readLine()) != null){

buffer.append(line);

}

return buffer.toString();

}

抱歉!评论已关闭.