Posted on 2011-05-13 11:48
xsong 閱讀(4921)
評論(0) 編輯 收藏 所屬分類:
java
1.OutputStream寫入String
ByteArrayOutputStream baos = new ByteArrayOutputStream();
//向OutPutStream中寫入,如 message.writeTo(baos);
String str = baos.toString();
2.字符串轉inputStream
String string;
//
InputStream is = new ByteArrayInputStream(string.getBytes());
3.InputStream轉字符串
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int i;
while ((i = is.read()) != -1) {
baos.write(i);
}
String str = baos.toString();
System.out.println(str);
4.String寫入OutputStream
OutputStream os = System.out;
os.write(string.getBytes());