Java Console readPassword() MethodThe readPassword() method of Java Console class reads a password or passphrase from the console with echoing disabled. SyntaxParametersN/A (not applicable, not available) Return value:This method returns a character array which contains the password read from the console. It does not include the line termination character. If an end of the stream has been reached, this method will return null. Exception:IOError: If an I/O error occurs. Example 1Output: Enter the password: @javatpoint Password is: @javatpoint Example 2Output: Enter the password: Rahul Your name is: Rahul Enter the password: rahul123 Your Password is: rahul123 Java Console readPassword(String fmt, Object args) MethodThe readPassword(String fmt, Object args) method of Console class provides a formatted prompt, then reads a password from the console. The program can read user input from the command line without showing what the user is typing. SyntaxParametersfmt: A format string as described in Format string syntax for the prompt text. args: Arguments referenced by the format specifiers in the format string. Return value:This method returns a character array which contains the password read from the console. It does not include the line termination character. If an end of the stream has been reached, this method will return null. Exception:IllegalFormatException: If given the format string is incompatible and insufficient arguments. Example 1Output: Your Name: Jony Name is: Jony Show password, please Enter Press: Password is: [C@1909752 Example 2Output: Your Name: Rahul Name is: Rahul Show old password, please Enter Press: Password is: [C@1909752 Update password: rahul1234 New Password is: rahul1234
Next TopicJava Console Class
|