Console read Password : Console « JDK 6 « Java






Console read Password

  

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 password = new String (console.readPassword ("Enter password: "));
    System.out.println(password);
  }
}

          
  








Related examples in the same category

1.Java Console readLine
2.Password Prompting with java.io.Console
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?