Java review
I/O flow:
1
1) According to the data flow direction:
input stream, output stream;
2) According to data processing unit:
byte stream, character stream;
3) According to function:
node stream, processing stream;
2
All flows in java.io.* are inherited from the following four categories;
3
Nodal flow: read data directly from the data source;
processing flow: on the basis of the existing flow, through the existing flow Processing provides programs with more powerful reading and writing capabilities;
4
InputStream
The class inheriting InputSteam is used to input data to the program
. The basic unit of input data: byte (8bit)
basic method:
int read( ) throws IOException
int read(byte[ ] buffer) throws IOException
int read(byte[ ] buffer,int offset,int length)throws IOException
void close( ) throws IOException
Note: The
read method is a blocking method. It
returns the number of bytes actually read. When the end of the file is reached, it returns -1
5
OutputStream
The class that inherits OutputStream is used for the program to output
data. Unit of data: byte (8bit)
basic method:
int write(int b) throws IOException
int write(byte[ ] b) throws IOException
int write(byte[ ] b,int offset,int length)throws IOException
void flush( ) throws IOException
void close( ) throws IOException
Flush will clear the cache, that is, write the cached data to the file. Close is to close the file in a general program. Call flush(
) before calling close() to write the buffer data to the disk.
6
Reader
inherits the Reader class and is used to input characters into the program.
The unit of data is character (16bit)
basic method
int read( ) throws IOException
int read(char[ ] cbuf) throws IOException
int read(char[ ] cbuf,int offset,int length) throws IOException
void close( ) throws IOException
7
Writer
inherits the class of Writer and is used to output characters
from the program . The unit of data is character (16bit). The
basic method
void write(int c) throws IOException
void write(char[ ] cbuf) throws IOException
void write(char[ ] cbuf,int offset,int length) throws IOException
void write(String string) throws IOException
void write(String string, int offset, int length) throws IOException
void close( ) throws IOException
void flush( ) throws IOException
8