Java Console readLine : Console « JDK 6 « Java






Java Console readLine

  


import java.io.Console;
import java.sql.SQLException;

public class MainClass {
  public static void main(String[] args) throws ClassNotFoundException, SQLException {
    Console console = System.console();
    if (console == null) {
      System.err.println("sales: unable to obtain console");
      return;
    }

    String username = console.readLine("Enter username: ");
    System.out.println(username);
  }
}

          
  








Related examples in the same category

1.Password Prompting with java.io.Console
2.Console read Password
3.Console output with format
4.Printing text with the Console class
5.Masking a password with the Console class
6.Use Console class to read user input?