Read line of characters from console using InputStream
- /*
- Read line of characters from console using InputStream
- This example shows how to read a line or string from console window
- using readLine method of BufferedInputStream.
- */
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- public class ReadLineFromConsoleExample {
- public static void main(String[] args) {
- /*
- * To read line or string from console use,
- * readLine method of BufferedReader class.
- */
- BufferedReader br =
- new BufferedReader(new InputStreamReader(System.in));
- String strLine = null;
- System.out.println("Reading line of characters from console");
- System.out.println("Enter exit to quit");
- try
- {
- while( (strLine = br.readLine()) != null)
- {
- if(strLine.equals("exit"))
- break;
- System.out.println("Line entered : " + strLine);
- }
- br.close();
- }
- catch(Exception e)
- {
- System.out.println("Error while reading line from console : " + e);
- }
- }
- }



