Class IO

java.lang.Object
java.io.IO

public final classIOextendsObject
IO is a preview API of the Java platform.
Programs can only useIO 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 tosystem console for implicitly declared classes.

Each of this class' methods throwsIOError if the system console isnull; 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 byConsole.charset().

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
    Terminates the current line on 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.
    staticString
    Reads a single line of text from the system console.
    staticString
    readln(String prompt)
    Writes a prompt as if by callingprint, then reads a single line of text from the system console.
  • 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.

      The effect is as ifprintln(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

      public static void println()
      Terminates the current line on the system console and then flushes that console.

      The effect is as ifprintln()PREVIEW had been called onSystem.console().

      Throws:
      IOError - ifSystem.console() returnsnull, or if an I/O error occurs
      Since:
      24
    • print

      public static void print(Object obj)
      Writes a string representation of the specified object to the system console and then flushes that console.

      The effect is as ifprint(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

      public static String readln(String prompt)
      Writes a prompt as if by callingprint, then reads a single line of text from the system console.

      The effect is as ifreadln(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. Returnsnull if 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

      public static String readln()
      Reads a single line of text from the system console.

      The effect is as ifreadln()PREVIEW had been called onSystem.console().

      Returns:
      a string containing the line read from the system console, not including any line-termination characters. Returnsnull if 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