Class IO

java.lang.Object
java.io.IO

public class IO extends Object
IO is a preview API of the Java platform.
Programs can only use IO when preview features are enabled.
Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.
A collection of static convenience methods that provide access to system console for implicitly declared classes.

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.

Since:
23
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Writes a string representation of the specified object to the system console and then flushes that console.
    static void
    Writes a string representation of the specified object to the system console, terminates the line and then flushes that console.
    static String
    readln(String prompt)
    Writes a prompt as if by calling print, then reads a single line of text from the system console.

    Methods declared in class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • println

      public static void println(Object obj)
      Writes a string representation of the specified object to the system console, terminates the line and then flushes that console. If System.console() returns null, throws IOError. Otherwise, the effect is as if println(obj)PREVIEW had been called on System.console().
      Parameters:
      obj - the object to print
    • print

      public static void print(Object obj)
      Writes a string representation of the specified object to the system console and then flushes that console. If System.console() returns null, throws IOError. Otherwise, the effect is as if print(obj)PREVIEW had been called on System.console().
      Parameters:
      obj - the object to print
    • readln

      public static String readln(String prompt)
      Writes a prompt as if by calling print, then reads a single line of text from the system console. If System.console() returns null, throws IOError. Otherwise, the effect is as if readln(prompt)PREVIEW had been called on System.console().
      Parameters:
      prompt - the prompt string
      Returns:
      a string containing the line read from the system console, not including any line-termination characters. Returns null if an end of stream has been reached without having read any characters.