Flow :
Concept: The operation of a file in Java is done in a streaming fashion. A stream is an ordered set of data sequences in Java memory. Java reads the data from the source (file, memory, keyboard, network) into memory, forms a stream, and then writes those streams to another destination (file, memory, console, network), which is called a stream because the data sequence operates at different points in different parts of the source.
Understanding: A stream, can be seen as a pipe, the data used to read the file raw data are used in the form of binary data transmission
In/out Flow
Classification of streams
Follow the direction of the data flow
Input stream, output stream
Input stream: Move data from file to program
Output stream: From the program to the file to go data
The data is processed in different units:
The eight data types Occupy bytes:
BYTE (1), short (2), int (4), Long (8)
Float (4), double (8)
Boolean (1)
CHAR (2)
Byte stream (ends with stream), character stream (ends with reader, writer)
BYTE stream: 8 bits of bytes, read data in one byte
Character stream: Two bytes, one character per unit
According to the function of:
node flow, processing flow
Node stream: Only one root pipe sleeve is transferred on the file
Process flow: Process the node flow, enhance the function of the pipeline, equivalent to a layer on the pipe
The stream provided by the JDK
Provides four basic abstract classes: InputStream, OutputStream, Reader, Writer
Basic methods of InputStream:
int read (): Each time this method is called, a byte is read and returned as an integer
int read (byte[] buffer---buffer): Let the stream read one buffer at a time, and then unified processing, first exists in the buffer, the return value of int is to return the actual number of bytes read (the principle of damage to the hard disk)
int read (byte[] buffer, int offset, int length): is also a buffer that reads the number of bytes of length in buffer, which is saved from the offset position of buffer, and the return value is the actual number of words read Number of knots
Close (): Close Resource
Basic methods of OutputStream:
void write (int b)
void Write (byte[] b)
int Wirte (byte[] buffer, int offset, int length)
Close ()
Flush (): Writes out all the files in the buffer
In a good habit of using the flow, first flush, then close
Basic methods of Reader:
int read ()
int read (char[] c)
int read (char[] c, int offset, int length)
Close ()
Writer's basic methods:
void Write ()
void Write (char[] c)
void Write (char[] c, int offset, int length)
Write a string directly out, inside the string there is a method S.tochararray (), check API
void Write (String s)
void Write (String s, int offset, int length)
Close ()
Flush ()
BufferedReader
ReadLine ()---reads a row each time it is called
BufferedWriter
WriteLine (String s)---write one line per call
Java Stream (i)