Java Console.readLine()

Syntax

Console.readLine() has the following syntax.

public String readLine()

Example

In the following code shows how to use Console.readLine() method.


/* w w w . j ava 2s.c o m*/
import java.io.Console;

public class Main {
  public static void main(String[] args) throws Exception {

    Console cnsl = System.console();

    if (cnsl != null) {

      String name = cnsl.readLine("Name: ");

      System.out.println("Name entered : " + name);
    }

  }
}

The code above generates the following result.