扫描仪与BufferedReader [英] Scanner vs. BufferedReader
本文介绍了扫描仪与BufferedReader的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Scanner
或 BufferedReader code>。我也知道 BufferedReader
通过使用缓冲区来有效地读取文件,以避免物理磁盘操作。我的问题是:
$ b
-
Scanner
的表现和 BufferedReader
? Scanner
over BufferedReader
或反之亦然?解决方案
BufferedReader
只是读取流,不做任何特殊的解析。
实际上,您可以将 BufferedReader
作为字符的来源传递给 scanner
解析。
As far I know, the two most common methods of reading character-based data from a file in Java is using Scanner
or BufferedReader
. I also know that the BufferedReader
read files efficiently by using a buffer to avoid physical disk operations. My questions are:
- Does
Scanner
performs as well asBufferedReader
? - Why would you choose
Scanner
overBufferedReader
or vice versa?
解决方案
Scanner
is used for parsing tokens from the contents of the stream while BufferedReader
just reads the stream and does not do any special parsing.
In fact you can pass a BufferedReader
to a scanner
as the source of characters to parse.
这篇关于扫描仪与BufferedReader的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文