Explain how to read a line of input at a time

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);
         }
      }
   }
}
How does Java handle integer overflows and underflows?
If a type exceeds a range of a type, it results in an overflow...
Difference between Integer and int in java
int is one of the primitive datatypes in Java. The Integer class wraps a value of the primitive type int in an object....
What is javap?
The javap is a command that disassembles a class file. It prints out the package.....
Post your comment