Search code examples
javaconsolebufferedinputstream

InputStreamReader or Console for Java I/O


To get user input in Java which is the better method?

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

or by use of Console--> Console c = System.console();

what is the difference between the two and which one is to be used. Or is there any other better method other than these two?


Solution

  • Console was introduced recently to Java (Java 6) to make reading and writing to the command line easier. Therefore, I would use Console.