Reading Text from Standard Input - Java Language Basics

Java examples for Language Basics:Console

Description

Reading Text from Standard Input

Demo Code

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

public class Main {
  public static void main(String[] argv) {
    try {/*from  w  ww.j  av  a2 s .  c  o m*/
      BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
      String str = "";
      while (str != null) {
        System.out.print("> prompt ");
        str = in.readLine();
        System.out.println(str);
      }
    } catch (IOException e) {
    }
  }
}

Result


Related Tutorials