Hi there! I was reading about 7th lesson of second level(keyboard input).But actually its like to fall into the ocean immidiately.There's no lesson that I can match the informations with each other.the topic talks about keyboard input but the examples including bufferedreader inputstream and etc.Don't even know where to start to get it.Bcause the lecture is about to make objects and reading data from files,creating buffered thing but have no idea how to complete the task without knowing all these things.Can you guys tell me a way to understand all these things?What should I know for understanding those?
Пример 1
Ввод строки и числа с клавиатуры
InputStream inputStream = System.in;
Reader inputStreamReader = new InputStreamReader(inputStream);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String name = bufferedReader.readLine(); //Read a string from the keyboard
String sAge = bufferedReader.readLine(); //Read a string from the keyboard
int nAge = Integer.parseInt(sAge); //Convert the string to a number.
azizbeyli
Level 3
keyboard input!
Under discussion
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
Aleksei Software Engineer at CiscoExpert
18 January 2023, 18:50
For the moment, you should use this structure for reading from console input as it is. Don't spend your valuable time to understand the implementation, because it makes no sense in the beginning.
0
hidden #598481
18 January 2023, 13:24
Where exactly do you have your grey area, can you please specify?
TL;DR All the details under the hood don't worth your time to dive deep now, you can just remember that BufferedReader is a type of object that can have an access to input data and let user to read a single line from console into a String object using readLine() method. That's it, as simple as it is.
BufferedReader is a reader i.e. the tool that you use to read and System.in is a standard input stream, it is a source that you are reading from. You can learn more about standard stream (stdin) in operating system but it is a bit out of scope for you now. In any java program stdin is represented by an object which is stored in System.in variable. To read from this stream you need to create a reader object, and that is exactly what you are doing. InputStreamReader is a type of simple reader that lets you read a single byte out of stream, and you wrap it into BufferedReader, which uses InputStreamReader under the hood: with a help of it it reads byte after byte before it meets line separator and after meeting one it returns you a String which is made of all bytes that were read.
But I'd like to repeat one more time that is it too much details for a newcomer, you can just remember, that this construction creates you a reader object which can read you a line from stdin: There is no need to store every single piece of it into separate variable because you are not going to use this variables later on, you just need this object to create this reader and that's it.
0