BufferedReader readLine Example

BufferedReader class readLine example. This example shows you how to use readLine method.


BufferedReader class readLine example. throws IOException Reads a line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed.

Here is the code
/*
 * @ # ReadLine.java
 * A class repersenting use to readLine method 
 * of BufferedReader class in java.io package
 * version 29 May 2008
 * author Rose India 
 */

import java.io.*;

public class ReadLine {

    public static void main(String[] argsthrows Exception {

        // Create a new instance of a BufferedReader object using
        // a StringReader.
        //String s = "This is the internal StringReader buffer.";
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader bufReader = new BufferedReader(isr);

        // Read from the underlying StringReader.
        System.out.println("Enter a string");
        String str = bufReader.readLine();
        System.out.println("Enter a integer");
        int i = Integer.parseInt(bufReader.readLine());
        System.out.println("String is " + str);
        System.out.println("Integer is " + i);
    }
}

Output
Enter a string Komal
Enter a integer 27
String is Komal
Integer is 27

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US