Explain how to read a line of input at a time.
Reading a line of input at a time is done by using console’s input stream , the System.in. This object is wrapped by an InputStreamReader. InputStreamReader reads the data in binary stream one character at a time and converts it to character stream. To read the data at a time, BufferedReader is wrapped around the InputStreamReader. The method readLine() of BufferedStream reads the line of characters.
Example :String str;
BufferedReader br = new BufferedReader(InputStreamReader(System.in));
str = br.readLine();
Explain how to read a line of input at a time.
Input from the console is read from the System.in object and is then wrapped by an InputStreamReader which reads one character at a time.
To read this data a line at a time, a BufferedReader is wrapped around the InputStreamReader.
class MyReader
{
public static void main(String[] args) throws IOException
{
String s = "";
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(isr);
// type 00 to exit from the program
while (!(s.equals("00")))
{
s = in.readLine();
if (!(s.equals("00")))
{
System.out.println(s);
}
}
}
}