Java IO package explanation
The inheritance relationship of the IO class is as follows:
Byte stream:
Character stream:
There is no need to talk about the specific use, and roughly talk about the relationship:
Byte stream and character stream
The byte stream is to read and read the file in the form of bytes.
Suitable for operation 图片
, 程序
and other non-text files
The character stream is to read and read the file in the form of characters.
Suitable for operation文本文件
Byte stream
InputStream
Sum OutputStream
is a base class and cannot be used directly
FileInputStream
Reading byte by byte requires a lot of IO operations
BufferedInputStream
It reads the bytes into the cache first, and then performs a one-time operation. The number of IO operations is small and the efficiency is high.
BufferedInputStream
Need to FileInputStream
be constructed by
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(f));
FileOutputStream
And the BufferedOutputStream
same
Character stream
Reader
Sum Writer
is a base class and cannot be used directly
FileReader
And BufferReader
relationships with FileInputStream
and BufferedInputStream
are similar, and even the structure is the same way
However, InputStreamReader
and BufferedReader
the relationship is a bit more complicated
because InputStreamReader
a byte character bridge, so InputStreamReader
you need to use FileInputStream
to create, then, can be used to createBufferedReader
OutputStreamWriter
, FileWriter
, BufferWriter
Relationship between the three above