• 字节内存流 | OutputStream{abstract} | | InputStream{abstract} | | | :—-: | :—-: | —- | —- | | FileOutputStream | ByteArrayOutputStream | FileInputStream | ByteArrayInputStream |

    • 字符内存流 | Writer{abstract} | | Reader{abstract} | | | :—-: | :—-: | —- | —- | | OutputStreamWriter | CharArrayWriter | InputStreamReader | CharArrayReader | | FileWriter | | FileReader | |

    • 字节内存流和字符内存流唯一的区别在于操作数据类型
    • 内存流的关闭是无效

    • 构造函数(以字节内存流为例)

    public ByteArrayOutputStream() 内存输出流,从内存向程序( 内存)输出
    public ByteArrayInputStream(bytes[] buf) 内存输入流,向内存输入
    程序也是在内存中的,实质上完全可以自己用byte[]来实现内存流

    1. String string="zhou_xv_de_string";
    2. //字节内存输出流,其write函数是向对象内的 byte buf[] 中写入
    3. ByteArrayOutputStream bao=new ByteArrayOutputStream();
    4. //字节内存输入流,构造时传入字节数组作为内存缓冲区,read函数从这个缓冲数组中读取
    5. ByteArrayInputStream bai=new ByteArrayInputStream(string.getBytes(StandardCharsets.UTF_8));
    6. int temp;
    7. while((temp=bai.read())!=-1){
    8. bao.write(Character.toUpperCase(temp));
    9. }
    10. System.out.println(bao);
    11. bao.close();
    12. bai.close();