Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Command line IO

 
Michael Anderson
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My Java Program is to be executed from the command line, reading and writing to/from the command window. It will prompt for SQL data connection parameters. Ea: Servername, Basename, Username, and Password.

java myjavaprog

Enter Server Name? myserver
Enter Database? mybase
Enter User name? me
Enter Password? symb0l1c

Q: When the user is typing the password into this character mode prompt, how do I (the programmer)turnoff the echo to the command window so that no one can see the password being typed by the user?

Thanks in Advance,
Mike.

With 1/4 century of programming experience, yet I am a Java Greenhorn.
 
Rob Spoor
Sheriff
Pie
Posts: 20526
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're using Java 1.6, take a look at java.io.Console. This has a method called readPassword() which turns off echoing.
 
Michael Anderson
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks! That is what I needed.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic