数组、字符串流

来源:互联网 发布:淘宝如何看自己退货率 编辑:程序博客网 时间:2024/05/16 08:32
 * ByteArrayInputStream 字节数组输入流
 * 
 * ByteArrayOutputStream  字节数组输出流
 * 
 * CharArrayReader 字符数组写入流
 * 
 * CharArrayWriter  字符数组输出流
 * 
 * StringReader  字符串写入流
 * 
 * StringWriter  字符串输出流
 * 
public static void method_1(){//从输入流的字符数组中读取到内存中,即写入到内存ByteArrayInputStream bais                                     = new ByteArrayInputStream("abcdefg".getBytes());//从内存中读取到输出的字节数组中,即从内存输出ByteArrayOutputStream baos = new ByteArrayOutputStream();int len = 0;while((len = bais.read())!=-1){baos.write(len);}System.out.println(baos.toString());}--------------------------------------------------------public static void method_2() throws Exception{CharArrayReader car = new CharArrayReader("abcdefghijk".toCharArray());CharArrayWriter caw = new CharArrayWriter();int len = 0;while((len = car.read())!=-1){caw.write(len);}System.out.println(caw.toString());}public static void method_3() throws Exception{StringReader sr = new StringReader("ABCDEFG");StringWriter sw = new StringWriter();int len = 0;while((len = sr.read())!=-1){sw.write(len);}System.out.println(sw);}


原创粉丝点击