Class IO
IO is a preview API of the Java platform.
Each of this class' methods throws IOError if the system console
is null; otherwise, the effect is as if a similarly-named method
had been called on that console.
Input and output from methods in this class use the character set of
the system console as specified by Console.charset().
- Since:
- 23
-
Method Summary
All MethodsStatic MethodsConcrete MethodsModifier and TypeMethodDescriptionstatic voidWrites a string representation of the specified object to the system console and then flushes that console.static voidprintln()Terminates the current line on the system console and then flushes that console.static voidWrites a string representation of the specified object to the system console, terminates the line and then flushes that console.static Stringreadln()Reads a single line of text from the system console.static StringWrites a prompt as if by callingprint, then reads a single line of text from the system console.
-
Method Details
-
println
Writes a string representation of the specified object to the system console, terminates the line and then flushes that console.The effect is as if
println(obj)PREVIEW had been called onSystem.console().- Parameters:
obj- the object to print, may benull- Throws:
IOError- ifSystem.console()returnsnull, or if an I/O error occurs
-
println
-
print
Writes a string representation of the specified object to the system console and then flushes that console.The effect is as if
print(obj)PREVIEW had been called onSystem.console().- Parameters:
obj- the object to print, may benull- Throws:
IOError- ifSystem.console()returnsnull, or if an I/O error occurs
-
readln
Writes a prompt as if by callingprint, then reads a single line of text from the system console.The effect is as if
readln(prompt)PREVIEW had been called onSystem.console().- Parameters:
prompt- the prompt string, may benull- Returns:
- a string containing the line read from the system console, not
including any line-termination characters. Returns
nullif an end of stream has been reached without having read any characters. - Throws:
IOError- ifSystem.console()returnsnull, or if an I/O error occurs
-
readln
Reads a single line of text from the system console.The effect is as if
readln()PREVIEW had been called onSystem.console().- Returns:
- a string containing the line read from the system console, not
including any line-termination characters. Returns
nullif an end of stream has been reached without having read any characters. - Throws:
IOError- ifSystem.console()returnsnull, or if an I/O error occurs- Since:
- 24
-
Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples. Other versions.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2025, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.
IOwhen preview features are enabled.