Use Of BufferedReader Class in Java for Accepting Input from User

Program using BufferedReader Class for accepting name entered for user through keyboard.

\\ If you have any query or questions on my post then please comment below //

Which Stream To Use ?
Java provides a useful input stream known as DataInputStream, which offers methods for reading characters,integers,floats etc.However only one constructor is defined for the class:
           java.io.DataInputStream(java.io.InputStream)


Within Java, streams are designed to be layered on top of each other that the programmer must connect together several streams to get the exact type of required functionality.I/O streams can be easily connect to one another by passing one stream as an argument to the other stream constructor eg,
              
          BufferedReader br=new BufferedReader(new FileReader(selectFile));


BufferedReader Class : This class contains a buffer for the data read and thus makes it  possible to have methods like readLine() which reads a line of data from the file and returns null if there are no more lines to read.The BufferedReader can be seen as a handle to the file you want to read from.

Syntax : 
                InputStreamReader input = new InputStreamReader(System.in); 
                BufferedReader br= new BufferedReader(input);


Program
import java.io.*;
class Print                           // class name 
{
    // create BufferedReader Class instance   
InputStreamReader input = new InputStreamReader(System.in); 
BufferedReader br= new BufferedReader(input);
public void demo() throws IOException
{
String name;
System.out.println("What is your name ?");
name=keyboardInput.readLine();
System.out.print("\nHello"+name);


Output
What is your name ?
Amit
 
Expert Review:  This program will help you to read the input given by the users from keyboard as there are many methods but this method is the best and simplest , easy code as well as shorter codes which will be eas for you to remeber.

Click Here To Know How To Download Above Video Tutorials Or YouTube Videos Free


 Enter Your Email Id To Get Our Programming, Web Development, Video Tutorial, Job Updates In Mail :

Labels: ,