BufferedReader vs Console vs Scanner

后端 未结 3 755
日久生厌
日久生厌 2020-12-04 09:26

Hi I\'m new to Java and I would like to know what is the best choice to read a user Input in the console, as far as I know there are 3 ways to do it:

3条回答
  •  悲&欢浪女
    2020-12-04 10:02

    Console class is implemented in a platform independent way to handle the console input for different Os. All OS has a console/shell but they are quite different in implementation. So Console class gives you a Java platform independent runtime class to access things like password input, etc.

    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.

提交回复
热议问题