kr.mayank1997
kr.mayank1997

Reputation: 21

Input in Java without pressing enter

I want to take any input in Java without pressing the enter key. Actually I want to make a password input program, so that as soon as the user enter any character, I can clear the screen and replace the characters with an equal number of asterisks ("*"), like the typical password entries made anywhere in the web. Most importantly, I would like to do the same in the Java Terminal Window, not by using those applet methods. Please tell me if i would have to supply more details. I am using BlueJ.

Thank you, Mayank.

Upvotes: 2

Views: 2175

Answers (1)

Bart Kiers
Bart Kiers

Reputation: 170158

You may want to have a look at the Console's readPassword(...) methods (needs Java 6+).

Or, when using Java 5 (or less), have a look at this article: Password Masking in the Java Programming Language, especially the paragraph Command-Line Input Masking.

Upvotes: 3

Related Questions