Package Summary Overview Summary

# Class IO

java.lang.Object
java.lang.IO

public final class IO extends Object
A collection of static methods that provide convenient access to `System.in` and `System.out` for line-oriented input and output.

The `readln()` and `readln(String)` methods in this class use internal objects that 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. These internal objects are created upon the first call to either of the `readln` methods and are stored for subsequent reuse by these methods.

The internal objects used by the `readln` methods may buffer additional bytes beyond those that have been decoded to characters returned to the application. The result of interleaving calls to the `readln` methods with other operations on `System.in` is unspecified.

Since:
  25

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static void`
  `print (Object obj)`
  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 (Object obj)`
  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 (String prompt)`
  Writes a prompt and then reads a line of input.

  ### Methods declared in class 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 and then writes a line separator to the standard output.

    The effect is as if `println(obj)` had been called on `System.out`.

    Parameters:
      `obj` - the object to print, may be `null`

  - ### println

    public static void println()
    Writes a line separator to the standard output.

    The effect is as if `println()` had been called on `System.out`.

  - ### print

    public static void print (Object obj)
    Writes a string representation of the specified object to the standard output.

    The effect is as if `print(obj)` had been called on `System.out`.

    Parameters:
      `obj` - the object to print, may be `null`

  - ### readln

    public static String readln()
    Reads a single line of text from the standard input.

    If necessary, this method first creates internal objects that decode the bytes read from the standard input into characters. These objects are retained for subsequent reuse by this method.

    One line is read from the decoded input as if by `BufferedReader.readLine()` and then the result is returned.

    Returns:
      a string containing the line read from the standard input, not including any line separator characters. Returns `null` if an end of stream has been reached without having read any characters.
    Throws:
      `IOError` - if an I/O error occurs

  - ### readln

    public static String readln (String prompt)
    Writes a prompt and then reads a line of input.

    Writes a prompt as if by calling `print`, and then reads a single line of text as if by calling `readln()`.

    Parameters:
      `prompt` - the prompt string, may be `null`
    Returns:
      a string containing the line read from the standard input, not including any line separator characters. Returns `null` if an end of stream has been reached without having read any characters.
    Throws:
      `IOError` - if an I/O error occurs