How to take input using BufferedReader in Java?

0 votes
Can someone explain me the method of taking input by using BufferedReader in Java?
Mar 4, 2019 in Java by Shruti

2 answers to this question.

0 votes

BufferedReader is used to decrease the time for taking input. Generally, we use the Scanner class.

BufferedReader inp = new BufferedReader (new InputStreamReader(;
int T= Integer.parseInt(inp.readLine()); // for taking a number as an input 
String str = inp.readLine(); // for taking a string as an input

For the case of an integer, you can take only input per line.

answered Mar 4, 2019 by Priyaj
• 57,450 points
0 votes

Reading User's Input using BufferedReader class:

By wrapping the (standard input stream) in an InputStreamReader which is wrapped in a BufferedReader, we can read input from the user in the command line. Here’s an example:

BufferedReader reader = new BufferedReader(new InputStreamReader(;
System.out.print("Enter your name: ");
String name = reader.readLine();
System.out.println("Your name is: " + name);

In the above example, the readLine() method reads a line of text from the command line.

answered Aug 16, 2019 by Sirajul
• 44,350 points

Related Questions In Java

0 votes
1 answer

How to encode data using Base64 in Java?

import org.apache.commons.codec.binary.Base64; We can not use sun.* packages ...READ MORE

answered May 30, 2018 in Java by Sushmita
• 6,880 points
0 votes
2 answers

How to convert an int array to string using tostring method in java?

Use java.util.Arrays: String res = Arrays.toString(array); System.o ...READ MORE

answered Aug 16, 2019 in Java by Sirajul
• 44,350 points
0 votes
1 answer

How to call a method after a delay in Android using Java?

final Handler handler = new Handler(); handler.postDelayed(new Runnable() ...READ MORE

answered Jun 11, 2018 in Java by Akrati
• 3,150 points
0 votes
1 answer

How to read an XML file using XPath in Java?

Import the packages required to work with ...READ MORE

answered Jun 14, 2018 in Java by Akrati
• 3,150 points
0 votes
1 answer

Are arrays equivalent to objects in Java ?

Yes; the Java Language Specification writes: In the Java ...READ MORE

answered May 10, 2018 in Java by Rishabh
• 3,540 points
0 votes
1 answer

Remove objects from an array in Java?

We can use external libraries: org.apache.commons.lang.ArrayUtils.remove(java.lang.Object[] array, int ...READ MORE

answered Jun 26, 2018 in Java by scarlett
• 1,280 points
0 votes
1 answer

Performance difference of if/else vs switch statement in Java

The thing you are worried about is ...READ MORE

answered Jul 26, 2018 in Java by geek.erkami
• 2,660 points
+1 vote
3 answers

What is the syntax to declare and initialize an array in java?

You can use this method: String[] strs = ...READ MORE

answered Jul 25, 2018 in Java by samarth295
• 2,190 points
+1 vote
2 answers

How to take multiple integer input in one line using BufferedReader in Java?

Try this in case you don't know ...READ MORE

answered Aug 29, 2019 in Java by Sirajul
• 44,350 points
+15 votes
18 answers

How can I convert String to JSON object in Java?

Hi @Daisy You can use Google gson  for more ...READ MORE

answered Feb 7, 2019 in Java by Suresh
• 700 points