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

IO style

insert image description here

IO stream overview

Java Io flow involves more than 40 classes. These classes look messy, but they are actually very regular, and there is a very close relationship between them. The more than 40 classes of Java Io flow are derived 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 processing data, 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 image description here

byte stream

Carousel: 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 image description here
Bullshit time:

If the guest officer thinks it is suitable to eat, can you give a free like! Thank you! Slow down guest officer! It is recommended to pack and collect, and come back next time. The shop's second QQ: 309021573, welcome to harass!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324156758&siteId=291194637