Java之ByteArrayInputStream和ByteArrayOutputStream-操作字节数组的类

ByteArrayInputStream和ByteArrayOutputStream

  源:内存中的字节数组

  目的:内存中的字节数组

这两个流对象不涉及底层资源的调用,操作的都是内存中的数组,所以不需要关闭,直接操作字节数组就可以了

 1 package FileDemo;
 2 
 3 import java.io.ByteArrayInputStream;
 4 import java.io.ByteArrayOutputStream;
 5 
 6 public class ByteArrayStreamDemo {
 7 
 8     /**
 9      * @param args
10      */
11     public static void main(String[] args) {
12 
13         ByteArrayInputStream bis = new ByteArrayInputStream("abcdef".getBytes());
14         ByteArrayOutputStream bos = new ByteArrayOutputStream();
15         int ch = 0;
16         while ((ch = bis.read()) != -1) {
17             bos.write(ch);
18         }
19         System.out.println(bos.toString());
20     }
21 
22 }

CharArratInputReader和CharArrayOutputWriter

  源:字符数组的字符流

  目的:字符数组的字符流

StringReader和StringWriter

  源:字符串的字符流

  目的:字符串的字符流

原文地址:https://www.cnblogs.com/ysw-go/p/5311534.html