IO流(2)—知识结构

来源:互联网 发布:阿里云cdn添加域名 编辑:程序博客网 时间:2024/05/29 13:44
  1. 结构:
    这里写图片描述

注:此IO包下主要介绍:
节点流:(字节流)FileInputStream、FileOutputStream、(字符流)Filereader、FileWriter
处理流(缓冲流):(字节流)BufferedInputStream、BufferedOutputStream、(字符流)BufferedReader、BufferedWriter
转换流:InputStreamReader、OutputStreamWriter
标准输入输出流:InputStream、OutputStream

  1. java.io.File类的使用

  2. io原理以及流的分类:
    按操作数据单位不同:字节流(8bit)主要处理除了文本文件以外的问文件、字符流(16bit)主要处理文本文件。
    按数据流的流向不同:输入流、输出流
    按流的角色不同:节点流(直接作用于文件的,可以从一个特定的数据源读写数据(文件、内存):FileInputStream、FileOutputSteam、FileReader、FileWriter)、处理流(除了以上四个之外都是,连接已存在的流(节点流、处理流)之上,通过对数据的处理为程序提供更为强大的功能)

    • 文件流(1):
      FileInputStream、FileOutputStream、FileReader、FileWriter
    • 缓冲流(1):
      BufferedInputStream、BufferedOutputStream
      BufferedReader、BufferedWriter
    • 对象流–序列化和反序列化(2):
      ObjectInputStream、ObjectOutputStream
    • 随机存取文件流(2):
      RandomAccessFile
    • 转换流(3):
      InputStreamReader、OutputStreamWriter
    • 标准输入、输出流
    • 打印流(4):
      PrintStream、PrintWriter
    • 数据流(4):
      DateInputStream、DateOutputStream

注:要求掌握的级别1-4

重要方法:

  • int read() throws IOException//读取一个字节并以正数的形式返回(0-255),结束返回-1
  • int read(byte[] b) throws IOException//读取一系列字节并存储到一个数组b,返回实际读取的字节数,结束返回-1
  • int read(byte[] b,int offset,int length) throws IOException
    //读取length个字节并存储到一个数组b,返回实际读取的字节数,结束返回-1
  • void close() throws IOException
  • int write() throws IOException//写入一个字节并以正数的形式返回(0-255),结束返回-1
  • int read(byte[] b) throws IOException//写入一系列字节并存储到一个数组b,返回实际读取的字节数,结束返回-1
  • int read(byte[] b,int offset,int length) throws IOException
    //写入length个字节并存储到一个数组b,返回实际读取的字节数,结束返回-1

注意:IO有非常多的知识点这里只是记录了一点,至于其他的知识点大家可以去网上自行查阅。

原创粉丝点击