Java – How to read input from System.console()

In Java, we can use System.console() to read input from the console. JavaSample.java package com.mkyong.io; import java.io.Console; public class JavaSample { public static void main(String[] args) { // jdk 1.6 Console console = System.console(); System.out.print("Enter your name: "); String name = console.readLine(); System.out.println("Name is: " + name); System.out.print("Enter your password: "); // Reads a password …

Read more

Java – How to read input from the console

In Java, there are three ways to read input from a console : System.console (JDK 1.6) Scanner (JDK 1.5) BufferedReader + InputStreamReader (Classic) 1. System.console Since JDK 1.6, the developer starts to switch to the more simple and powerful java.io.Console class. JavaConsole.java package com.mkyong.io; import java.io.Console; public class JavaConsole { public static void main(String[] args) …

Read more