Scanner vs. BufferedReader

前端 未结 12 1750
死守一世寂寞
死守一世寂寞 2020-11-22 02:17

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

12条回答
  •  有刺的猬
    2020-11-22 02:47

    There are different ways of taking input in java like:

    1) BufferedReader 2) Scanner 3) Command Line Arguments

    BufferedReader Read text from a character-input stream, buffering characters so as to provide for the efficient reading of characters, arrays, and lines.

    Where Scanner is a simple text scanner which can parse primitive types and strings using regular expressions.

    if you are writing a simple log reader Buffered reader is adequate. if you are writing an XML parser Scanner is the more natural choice.

    For more information please refer:

    http://java.meritcampus.com/t/240/Bufferedreader?tc=mm69

提交回复
热议问题