AI-generated Key Takeaways
-
The
Consoleclass provides access to the system console for reading input and writing output. -
It offers methods for reading lines, passwords (unimplemented on Android), and formatting output.
-
Consoleincludes functionalities for flushing buffered output and accessing associated Reader and Writer objects. -
A system-wide
Consoleinstance can be obtained usingSystem.console().
Provides access to the console, if available. The system-wide instance can
be accessed via System.console().
Public Method Summary
| void |
flush()
Flushes this stream by writing any buffered output to the underlying
stream.
|
| Console | |
| Console | |
| String |
readLine()
Reads a line from the console.
|
| String | |
| char[] |
readPassword()
This method is unimplemented on Android.
|
| char[] | |
| Reader | |
| PrintWriter |
Inherited Method Summary
Public Methods
public void flush ()
Flushes this stream by writing any buffered output to the underlying stream.
public Console format (String format, Object... args)
Writes a formatted string to the console using the specified format string and arguments.
Parameters
| format | the format string (see Formatter.format(String, Object...)) |
|---|---|
| args | the list of arguments passed to the formatter. If there are
more arguments than required by format,
additional arguments are ignored. |
Returns
- the console instance.
public Console printf (String format, Object... args)
Equivalent to format(format, args).
Parameters
| format | |
|---|---|
| args |
public String readLine (String format, Object... args)
Reads a line from this console, using the specified prompt.
The prompt is given as a format string and optional arguments.
Note that this can be a source of errors: if it is possible that your
prompt contains % characters, you must use the format string "%s"
and pass the actual prompt as a parameter.
Parameters
| format | the format string (see Formatter.format(String, Object...)) |
|---|---|
| args | the list of arguments passed to the formatter. If there are
more arguments than required by format,
additional arguments are ignored. |
Returns
- the line, or null at EOF.
public char[] readPassword ()
This method is unimplemented on Android.
public char[] readPassword (String format, Object... args)
This method is unimplemented on Android.
Parameters
| format | |
|---|---|
| args |