Article Directory
Classification IO streams
- According to dataDirection of flowDividedInput stream、Output 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 stream、Character 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 Stream、Process 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.如BufferedReader。Constructor 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
- The input stream or output stream
- Byte stream or a character stream
- 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); //输入流、字节流、处理流
2. The output byte stream
- OutputStream(Byte stream output stream) =》 FileOutputStream(Node output byte stream) =》 (Output byte stream processing -> process = buffer)
- OutputStream(Byte stream output stream) =》 FileOutputStream(Node output byte stream) =》 (Output byte stream processing -> = Print Processing)
OutputStream out = System.out; //输出流、字节流、节点流 (方便看,这里向上转型,原来是PrintStream)
new BufferedOutputStream(System.out); //输出流、字节流、处理流(缓冲)
new PrintStream(System.out); //输出流、字节流、处理流(换行)
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 ()
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);// 输出流、字符流、处理流(换行)