I am an IO stream, I am a ruthless machine!

IO style

Insert picture description here

IO stream overview

The java Io stream involves more than 40 classes. These classes look very messy, but they are actually very regular and have very close relations with each other. The more than 40 classes of the Java Io stream are all from the following 4 abstract classes Derived from the base class.

InputStream/Reader: 所有的输入流的基类,前者是字节输入流,后者是字符输入流。
OutputStream/Writer: 所有输出流的基类,前者是字节输出流,后者是字符输出流。
/**
     * IO流概述
     *  可以将这种数据传输操作,看做一种数据的流动 , 按照流动的方向分为输入Input和输出Output
     *  Java中的IO操作主要指的是 java.io包下的一些常用类的使用. 通过这些常用类对数据进行读取(输入Input) 和 写出(输出Output)
     *
     * IO流的分类:
     *  按照流的方向来分,可以分为:输入流和输出流.
     *  按照流动的数据类型来分,可以分为:字节流和字符流
     *
     *     字节流:
     *          -   输入流 :   InputStream
     *          -   输出流 :   OutputStream
     *     字符流:
     *          -   输入流 :   Reader
     *          -   输出流 :   Writer
     *
     *
     * 一切皆字节:
     *      计算机中的任何数据(文本,图片,视频,音乐等等)都是以二进制的形式存储的.
     *      在数据传输时 也都是以二进制的形式存储的.
     *      后续学习的任何流 , 在传输时底层都是二进制.
     * @param args
     */

Classification of IO streams

  • According to the different types of data to be processed, it is divided into: character stream and byte stream
  • According to the data flow direction, it is divided into: input stream and output stream
    Insert picture description here

Byte stream

Conveyor belt: byte stream

Character stream

Carousel: character stream

Byte-to-character stream

package work.february.two.daily;

import java.io.*;

/**
 * @Author: 小浪
 * @Description:
 * @Date Created in 2021-02-02 20:37
 * @Modified By:
 */
public class Demo11 {
    
    
    public static void main(String[] args) throws IOException {
    
    
        //转化流 字节转字符
        FileInputStream fileInputStream =new FileInputStream("D://d.txt");
        InputStreamReader inputStreamReader =new InputStreamReader(fileInputStream,"utf-8");
        while (true){
    
    
            int c = inputStreamReader.read();
            if(c==-1){
    
    
                break;
            }
            System.out.println((char)c);

        }

    }
}

package work.february.two.daily;

import java.io.*;

/**
 * @Author: 小浪
 * @Description:
 * @Date Created in 2021-02-02 20:44
 * @Modified By:
 */
public class Demo12 {
    
    
    public static void main(String[] args) throws IOException {
    
    
        FileOutputStream fileOutputStream =new FileOutputStream("D://c.txt");
        OutputStreamWriter outputStreamWriter =new OutputStreamWriter(fileOutputStream);
        outputStreamWriter.write("场子要货");
        outputStreamWriter.flush();
        outputStreamWriter.close();
    }
}

Insert picture description here
Nonsense time:

If the customer thinks that the food is appropriate, can you give a free like! Thank you! Slow walker officer! It is recommended to pack and collect and come again next time. Shop Xiaoer QQ: 309021573, welcome to harass!

Guess you like

Origin blog.csdn.net/AzirBoDa/article/details/113242555