日期:2014-05-20  浏览次数:20657 次

用一个字符串转换成一个流,有兴趣的进来讨论一下!
如题,今天老师给我出的题,不管是字符流还是字节流均可 欢迎大家讨论!

------解决方案--------------------
for example
Java code
String s = "1234567890abcdefg";
byte[] b = s.getBytes();
ByteArrayInputStream bis = new ByteArrayInputStream(b); //输入流
ByteArrayOutputStream bos = new ByteArrayOutputStream(); //输出流
bos.write(b, 0, b.length); //写到输出流

------解决方案--------------------
ByteArrayInputStream bis = new ByteArrayInputStream("abcdef".getBytes());

ByteArrayOutputStream bos = new ByteArrayOutputStream();

int ch = 0;
while ((ch = bis.read()) != -1) {
bos.write(ch);
}