String与InputStream互转 _JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > String与InputStream互转

String与InputStream互转

 2012/6/11 0:12:56  ruyun  程序员俱乐部  我要评论(0)
  • 摘要:1.String-->InputStreamInputStreamString2InputStream(Stringstr){ByteArrayInputStreamstream=newByteArrayInputStream(str.getBytes());returnstream;}2.InputStream-->StringStringinputStream2String(InputStreamis){BufferedReaderin=newBufferedReader
  • 标签:

1. String --> InputStream
InputStream String2InputStream(String str){
??? ByteArrayInputStream stream = new ByteArrayInputStream(str.getBytes());
??? return stream;
}

?

2. InputStream --> 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();
}

  • 相关文章
发表评论
用户名: 匿名