Java Console Class

The Java Console class is be used to get input from console. It provides methods to read texts and passwords.

If you read password using Console class, it will not be displayed to the user.

The java.io.Console class is attached with system console internally. The Console class is introduced since 1.5.

Java FilterInputStream class declaration

public final class Console extends Object implements Flushable

Java Console class methods

  1. Reader reader()

    It is used to retrieve the reader object associated with the console

  2. String readLine()

    It is used to read a single line of text from the console.

  3. String readLine(String fmt, Object... args)

    It provides a formatted prompt then reads the single line of text from the console.

  4. char[] readPassword()

    It is used to read password that is not being displayed on the console.

  5. char[] readPassword(String fmt, Object... args)

    It provides a formatted prompt then reads the password that is not being displayed on the console.

  6. Console format(String fmt, Object... args)

    It is used to write a formatted string to the console output stream.

  7. Console printf(String format, Object... args)

    It is used to write a string to the console output stream.

  8. PrintWriter writer()

    It is used to retrieve the PrintWriter object associated with the console.

  9. void flush()

    It is used to flushes the console.


How to get the object of Console

public static Console console(){}
Console c=System.console();

Java Console Example

Flash Soon


Output:



Advertisement

Copyright ©2017 Design& develop