Reading data from keyboardThere are many ways to read data from the keyboard. For example:
InputStreamReader classInputStreamReader class can be used to read data from keyboard.It performs two tasks:
BufferedReader classBufferedReader class can be used to read data line by line by readLine() method. Example of reading data from keyboard by InputStreamReader and BufferdReader classIn this example, we are connecting the BufferedReader stream with the InputStreamReader stream for reading the line by line data from the keyboard. Output:Enter your name Amit Welcome Amit Another Example of reading data from keyboard by InputStreamReader and BufferdReader class until the user writes stopIn this example, we are reading and printing the data until the user prints stop. Output:Enter data: Amit data is: Amit Enter data: 10 data is: 10 Enter data: stop data is: stop
Next TopicConsole class
|