bufferedreader和filereader之间的具体区别

bufferedreader和filereader之间的具体区别

本文介绍了bufferedreader和filereader之间的具体区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道 BufferedReader FileReader 之间的具体区别。

I would like to know the specific difference between BufferedReader and FileReader.

我知道 BufferedReader FileReader ,但有人可以解释原因(具体而详细)吗?谢谢。

I do know that BufferedReader is much more efficient as opposed to FileReader, but can someone please explain why (specifically and in detail)? Thanks.

推荐答案

以简单的方式:

FileReader类是从File中读取字符的通用工具。 BufferedReader类可以包含读取器,如FileReader,以缓冲输入并提高效率。因此,您不会使用其中一个,而是同时将FileReader对象传递给BufferedReader构造函数。

A FileReader class is a general tool to read in characters from a File. The BufferedReader class can wrap around Readers, like FileReader, to buffer the input and improve efficiency. So you wouldn't use one over the other, but both at the same time by passing the FileReader object to the BufferedReader constructor.

非常详细

FileReader用于从磁盘输入字符数据文件。输入文件可以是普通的ASCII,每个字符文本文件一个字节。 Reader流自动将字符从磁盘文件格式转换为内部char格式。输入文件中的字符可能来自UTF格式支持的其他字母表,在这种情况下,每个字符最多可包含三个字节。在这种情况下,文件中的字符也会被翻译成字母格式。

FileReader is used for input of character data from a disk file. The input file can be an ordinary ASCII, one byte per character text file. A Reader stream automatically translates the characters from the disk file format into the internal char format. The characters in the input file might be from other alphabets supported by the UTF format, in which case there will be up to three bytes per character. In this case, also, characters from the file are translated into char format.

与输出一样,最好使用缓冲区来提高效率。为此使用BufferedReader。这与我们用于键盘输入的类相同。这些行应该看起来很熟悉:

As with output, it is good practice to use a buffer to improve efficiency. Use BufferedReader for this. This is the same class we've been using for keyboard input. These lines should look familiar:

BufferedReader stdin =
    new BufferedReader(new InputStreamReader( System.in ));

这些行创建一个BufferedReader,但是将它连接到键盘的输入流,而不是文件。

These lines create a BufferedReader, but connect it to an input stream from the keyboard, not to a file.

来源:

这篇关于bufferedreader和filereader之间的具体区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 16:59