The java.lang.IO class provides simple methods for interactive console I/O. For standard console input, IO.readln() should be preferred over the traditional, more verbose BufferedReader.

Why is this an issue?

Traditionally, reading a line from the console required significant boilerplate code, involving InputStreamReader, BufferedReader, and explicit IOException handling. This pattern is not only verbose but also error-prone and harder to read.

The modern IO.readln() method:

How to fix it

Replace manual stream wrapping of System.in with the static IO.readln() method. If you are using a version of Java where IO is automatically imported (such as in JShell or modern entry points), you can call IO.readln() directly; otherwise, use import static java.lang.IO.readln;.

Code examples

Noncompliant code example

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

void main() {
    try {
        System.out.print("Enter text: ");
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String line = reader.readLine(); // Noncompliant: verbose boilerplate
        System.out.println(line);
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }
}

Compliant solution

import static java.lang.IO.readln;

void main() {
    // Compliant: concise and readable console input
    String line = readln("Enter text: ");
    System.out.println(line);
}

Resources

Documentation