Read a string from console using a BufferedReader. : Buffered Reader Writer « File Input Output « Java






Read a string from console using a BufferedReader.

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

class BRReadLines {
  public static void main(String args[]) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String str;

    System.out.println("Enter lines of text.");
    System.out.println("Enter 'stop' to quit.");
    do {
      str = br.readLine();
      System.out.println(str);
    } while (!str.equals("stop"));
  }
}

   
  








Related examples in the same category

1.Use a BufferedReader to read characters from the console.
2.Creates a tiny text editor with BufferedReader
3.how to read lines from a file and print these to the standard output stream
4.Writing to a Text File
5.Fast BufferedWriter