扫描仪与BufferedReader [英] Scanner vs. BufferedReader

查看:160
本文介绍了扫描仪与BufferedReader的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,从Java文件中读取基于字符的数据的两种最常见的方法是使用 Scanner BufferedReader code>。我也知道 BufferedReader 通过使用缓冲区来有效地读取文件,以避免物理磁盘操作。我的问题是:
$ b

  • Scanner 的表现和 BufferedReader

  • 为什么要选择 Scanner over BufferedReader 或反之亦然?

    解决方案

    Scanner code>用于从流的内容解析令牌,而 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 as BufferedReader?
    • Why would you choose Scanner over BufferedReader 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆