首页 > java > String和InputStream、Reader 的转换

String和InputStream、Reader 的转换

2009年10月14日 发表评论 阅读评论

1、String –> InputStream
InputStrem is = new ByteArrayInputStream(str.getBytes());
or
ByteArrayInputStream stream
= new ByteArrayInputStream(str.getBytes());
2、InputStream–>String
BufferedReader in = new BufferedReader(new InputStreamReader(is));
StringBuffer buffer = new StringBuffer();
String line = “”;
while ((line = in.readLine()) != null){
buffer.append(line);
}
return buffer.toString();
3、String–>Reader
Reader reader = null;
BufferedReader r = new BufferedReader(reader);
StringBuilder b = new StringBuilder();
String line;
while((line=r.readLine())!=null) {
b.append(line);
b.append(“\r\n”);
}
b.toString();

分类: java 标签: 4,471 次阅读
原文链接:http://www.wenhq.com/article/view_381.html
欢迎转载,请注明出处:亲亲宝宝
  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.