Java - IO streams - finishing relationship (simple)

Classification IO streams

  • According to dataDirection of flowDividedInput streamOutput stream

Input, output isWith respect to the code of the program we writeFor

  • Input stream: from somewhere else(Local files, network resources, etc.) access to resources
  • Output streams: from our programOutput elsewhere
  • pressDifferent data processing unitsDividedByte streamCharacter stream

Byte stream: each read (write) one byte 1Byte,Processing non-character file= "Audio, video. . .

Character stream: each read (write) two bytes 1Word = 2Byte. Processing character file = "Text

  • pressDifferent functionsDividedNode StreamProcess Flow

Node Stream: read and write data to a particular place (node) or from. Such as FileInputStream 
Process Flow: is an existing connection and package stream, By flow-encapsulated call for data write.如BufferedReaderConstructor processing flow is always to bring one other stream object as an argument. A stream object after several other packaging stream.

Note:

  • Only "input / output stream" can not be instantiated, must be "byte / character stream" as the connection (flow forming process), and then if necessary nested "process stream" outside
  • Look at the picture below you can read up!

Discrimination IO streams

Identification process

  1. The input stream or output stream
  2. Byte stream or a character stream
  3. Process flow stream or node

IO stream finishing

1. The input byte stream

  • InputStream(Byte input stream) =》 FileInputStream(Node input byte stream) =》 BufferedInputStream(Processing the input stream of bytes -> process = buffer)
InputStream in = System.in;  //输入流、字节流、节点流
new BufferedInputStream(System.in); //输入流、字节流、处理流

Here Insert Picture Description


2. The output byte stream

  • OutputStream(Byte stream output stream) =》 FileOutputStream(Node output byte stream) =》 B in f f e r e d O in t p in t S t r e a m {\color{#ff0011}{BufferedOutputStream}} Output byte stream processing -> process = buffer)
  • OutputStream(Byte stream output stream) =》 FileOutputStream(Node output byte stream) =》 P r i n t S t r e a m {\color{#ff0011}{PrintStream}} Output byte stream processing -> = Print Processing)
OutputStream out = System.out; //输出流、字节流、节点流  (方便看,这里向上转型,原来是PrintStream)
new BufferedOutputStream(System.out); //输出流、字节流、处理流(缓冲)
new PrintStream(System.out); //输出流、字节流、处理流(换行)

Here Insert Picture Description


3. Enter the character stream

  • Reader(Input character stream) =》 InputStreamReader (Enter the characters node stream) =》 BufferedReader(Process stream input node
//创建字符流实例,需要传入字节流实例
new InputStreamReader(System.in,"UTF-8"); //输入流、字符流、节点流 => 字符流有处理字符的功能
new BufferedReader(new InputStreamReader(System.in,"UTF-8")); //输入流、字符流、处理流(缓冲)

new Scanner(System.in)

Only BufferedReader can read lines readLine ()

Here Insert Picture Description


Output character stream

  • Writer(Output character stream) =》 OutputStreamWriter(Node output byte stream) =》 BufferedWriter (An output node processing stream
  • OutputStreamWriter(Node output byte stream) =》 BufferedWriter (An output node processing stream
//创建字符流实例,需要传入字节流实例
new OutputStreamWriter(System.out,"UTF-8"); //输出流、字符流、节点流 =》 字符流有处理字符的功能
new BufferedWriter(new OutputStreamWriter(System.out,"UTF-8")); //输出流、字符流、处理流(缓冲)
new PrintWriter(System.out);// 输出流、字符流、处理流(换行)

Here Insert Picture Description


to sum up

《Java-IO流》https://blog.csdn.net/sinat_37064286/article/details/86537354#1%E3%80%81%E6%B5%81%E7%9A%84%E6%A6%82%E5%BF%B5%E5%92%8C%E4%BD%9C%E7%94%A8

Here Insert Picture Description

Published 296 original articles · won praise 61 · views 7073

Guess you like

Origin blog.csdn.net/LawssssCat/article/details/103188942