InputStream、OutputStream、String的相互转换(转)

 

//1、字符串转inputStream
String string;
//......
InputStream is = new ByteArrayInputStream(string.getBytes());

//2、InputStream转字符串
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int i;
while ((i = is.read()) != -1) {
    baos.write(i);
}
String str = baos.toString();
System.out.println(str);

//3、String写入OutputStream
OutputStream os = System.out;
os.write(string.getBytes());

 

 

http://blog.csdn.net/crazy_fire/article/details/7653605

 

posted @ 2014-11-12 09:28  沧海一滴  阅读(1569)  评论(0编辑  收藏  举报