Classification and usage steps of commonly used IO streams

Classification of common IO streams

1. What is input? What is output?

 输入:把硬盘中的数据,读取到内存中使用
 输出:把内存中的数据,写入到硬盘中保存

2. Classification
Insert picture description here
3. Use steps (common)

1.字节输入流的使用步骤:
      1)创建一个FileOutputStream对象,构造方法传递写入数据的目的地
      2)调用FileOutPutStream对象中的方法Write,把数据写入到文件中
      3)释放资源

Example
Insert picture description here

2.字节输出流的使用步骤:
	  1)创建FileInputStream对象,构造方法中绑定要读取的数据源
	  2)使用FileInputStream对象中的方法read,读取文件
	  3)释放资源

Example
Insert picture description here

3.字符输出流的使用步骤:
	   1)创建FileWriter对象,构造方法中绑定要写入的数据的目的地
	   2)使用FileWriter中的方法write,把数据写入到内存缓冲区中(字符转换为字节的过程)
	   3)使用FileWriter中的方法flush,把内存缓冲区中的数据,刷新到文件中
	   4)释放资源

Example
Insert picture description here

4.字符输入流的使用步骤:
		1)创建FileReader对象,构造方法中绑定要读取的数据源
		2)使用FileReader对象中的方法read读取文件
		3)释放资源

Example
Insert picture description here
4. Comprehensive use case-file copy procedure
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_49092628/article/details/110408124