public final class IO extends Object
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.encoding 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.
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 | Method | Description |
|---|---|---|
static void |
print |
Writes a string representation of the specified object to the standard output. |
static void |
println() |
Writes a line separator to the standard output. |
static void |
println |
Writes a string representation of the specified object and then writes a line separator to the standard output. |
static String |
readln() |
Reads a single line of text from the standard input. |
static String |
readln |
Writes a prompt and then reads a line of input. |
public static void println(Object obj)
The effect is as if println(obj) had been called on System.out.
obj - the object to print, may be null
public static void println()
The effect is as if println() had been called on System.out.
public static void print(Object obj)
The effect is as if print(obj) had been called on System.out.
obj - the object to print, may be null
public static String readln()
One line is read from the decoded input as if by BufferedReader.readLine() and then the result is returned.
If necessary, this method first sets up charset decoding, as described in above in the class specification.
null if an end of stream has been reached without having read any characters.IOError - if an I/O error occurspublic static String readln(String prompt)
Writes a prompt as if by calling print, and then reads a single line of text as if by calling readln.
If necessary, this method first sets up charset decoding, as described in above in the class specification.
prompt - the prompt string, may be null
null if an end of stream has been reached without having read any characters.IOError - if an I/O error occurs
© 1993, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IO.html