Skip to main content

Posts

Showing posts with the label keyboard

How to read input from console (keyboard) in Java?

There are few ways to read input string from  your console/keyboard. The following smaple code shows how to read a string from the console/keyboard by using Java. public class ConsoleReadingDemo {     public static void main(String[] args) {         // ====         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));         System.out.print("Please enter user name : ");         String username = null;         try {             username = reader.readLine();         } catch (IOException e) {             e.printStackTrace();         }      ...