Tag Archives: system

Reading From StdIn


The StdIn class provides static methods for reading strings and numbers from standard input. These functions fall into one of four categories:

  • those for reading individual tokens from standard input, one at a time, and converting each to a number, string, or boolean
  • those for reading characters from standard input, one at a time
  • those for reading

The example below shows how you can use it to read input from the user;

try {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String str = "";
    while (str != null) {
        System.out.print("> prompt ");
        str = in.readLine();
} catch (IOException e) {