Java Java Data Structures Efficiency! Design the UI

Kevin Faust
Kevin Faust
15,343 Points

more information on this: new BufferedReader (new InputStreamReader(System.in));

new BufferedReader (new InputStreamReader(System.in));

i have no idea what this does and why we need it

2 Answers

Rob Bridges
Rob Bridges
13,602 Points

Hey Kevin,

What that line of code is effectively doing is using the Buffered Reader Class to set up an input steam that we can utilzye to read input from the keyboard.

A buffered reader is simply a class that we can call to help us read input from the keyboard for base Input output type of programs. at treehouse we've been using console.readLine(); but you'll find when you move to IDE's that console actually doesn't work. In which case we use one of two classes.

Buffered Reader

Or Scanner

Both of these classes assist with reading input type that is passed into the program.

Kevin Faust
Kevin Faust
15,343 Points

hey rob, thanks

is using BufferedReader and InputStreamReader the most common way to take in input?

Rob Bridges
Rob Bridges
13,602 Points

Hey Kevin,

Personally I like buffered Reader myself, but there are many people out there who use Scanner, I will use Scanner in the event that the input I am grabbing needs to be broken apart and looked at the word by word. this would be a job for the Scanner as it's better at breaking things down and buffered reader has trouble in that department.

However if you really just want to get the contents buffered reader would be better at this.