What does the Java – BufferedReader constructor expect from FileReader

I need to understand the differences between the two classes and how they work together As far as I know, FileReader reads characters from one file at a time, and BufferedReader reads a large amount of data and stores it in the buffer to make it faster

In order to use BufferedReader, I must provide a FileReader If the BufferedReader class reads files in different ways, how does it use FileReader? Does this mean that BufferedReader uses FileReader, so behind the scenes, characters can still be read only one character at a time? I think my question is how the BufferedReader class uses the FileReader class

Solution

First, BufferedReader uses reader instead of FileReader (although the latter is accepted)

The reader abstract class has several read () methods There is a read - one - character version and two versions that read a character block into an array

It makes sense to use BufferedReader only when reading a single character or small block at a time

Consider the following two requests:

char ch1 = fileReader.read();
char ch2 = bufferedReader.read()

The first will go to the underlying file, and the second will most likely be satisfied from the BufferedReader's internal buffer

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>