Here you can find the source of promptHidden(String message)
Parameter | Description |
---|---|
message | a parameter |
public static String promptHidden(String message)
//package com.java2s; //License from project: Open Source License import java.util.Scanner; public class Main { private static Scanner in = new Scanner(System.in); /**//w w w . jav a2s.c o m * Prompot user for input, hiding the input if possible. Useful for password input. * @param message * @return a line of user's input */ public static String promptHidden(String message) { if (System.console() != null) { System.out.print(message + ": "); char[] line = System.console().readPassword(); return new String(line); } return prompt(message); } /** * Prompt user for input. * @param message * @return a line of user's input */ public static String prompt(String message) { System.out.print(message + ": "); return in.nextLine().trim(); } /** * Prompt user for input, providing a default input. * @param message * @param defaults * @return a line of user's input */ public static String prompt(String message, String defaults) { System.out.print(message + " [" + defaults + "]: "); String line = in.nextLine().trim(); return line.equals("") ? defaults : line; } }