Created
November 18, 2014 19:07
-
-
Save ansig/53d5685ff4e9b58d0d2f to your computer and use it in GitHub Desktop.
Take in username and password from the console.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.Console; | |
/** | |
* Take in username and password from the console. | |
*/ | |
public class ConsoleInput { | |
public static void main(String[] args) { | |
Console console = System.console(); | |
if (console == null) { | |
System.out.printf("No console available, program not started in interactive shell%n"); | |
System.exit(1); | |
} | |
String username = console.readLine("Enter your username: "); | |
char[] password = console.readPassword("Hello %s, please enter your password: ", username); | |
System.out.printf("The entered password was: %s%n", new String(password)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment