System#in
and System#out for line-oriented input and output.
The readln() and readln(String) methods decode bytes read from
System.in into characters. The charset used for decoding is specified by the
stdin. property. If this property is not present,
or if the charset it names cannot be loaded, then UTF-8 is used instead. Decoding
always replaces malformed and unmappable byte sequences with the charset's default
replacement string.
Charset decoding is set up upon the first call to one of the readln methods.
Decoding may buffer additional bytes beyond those that have been decoded to characters
returned to the application. After the first call to one of the readln methods,
any subsequent use of System.in results in unspecified behavior.
API Note
The expected use case is that certain applications will use only the readln
methods to read from the standard input, and they will not mix these calls with
other techniques for reading from System.in.
| Modifier and Type | Field and Description |
|---|---|
| private static BufferedReader | br
The BufferedReader used by readln(). |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static void | |
| public static void | |
| public static void | |
| pack-priv static synchronized BufferedReader | Returns: the internal BufferedReader instanceOn the first call, creates an InputStreamReader to decode characters from System.in, wraps it in a BufferedReader, and returns the BufferedReader. |
| public static String | Returns: a string containing the line read from the standard input, not including any line separator characters. Returnsnull if an
end of stream has been reached without having read any characters.Reads a single line of text from the standard input. |
| public static String |
| br | back to summary |
|---|---|
| private static BufferedReader br The BufferedReader used by readln(). Initialized under a class lock by the reader() method. All access should be through the reader() method. | |
| IO | back to summary |
|---|---|
| private IO() | |
| back to summary | |
|---|---|
| public static void print(Object obj) Writes a string representation of the specified object to the standard output. The effect is as if
| |
| println | back to summary |
|---|---|
| public static void println(Object obj) Writes a string representation of the specified object and then writes a line separator to the standard output. The effect is as if
| |
| println | back to summary |
|---|---|
| public static void println() Writes a line separator to the standard output. The effect is as if | |
| reader | back to summary |
|---|---|
| pack-priv static synchronized BufferedReader reader() On the first call, creates an InputStreamReader to decode characters from System.in, wraps it in a BufferedReader, and returns the BufferedReader. These objects are cached and returned by subsequent calls.
| |
| readln | back to summary |
|---|---|
| public static String readln() Reads a single line of text from the standard input.
One line is read from the decoded input as if by
If necessary, this method first sets up charset decoding, as described in above in the class specification. | |
| readln | back to summary |
|---|---|
| public static String readln(String prompt) Writes a prompt and then reads a line of input.
Writes a prompt as if by calling If necessary, this method first sets up charset decoding, as described in above in the class specification.
| |