Java Technical Question:

read a line of input at a time in Java?

Tweet Share WhatsApp

Answer:

The standard input stream is represented by the InputStream object System.in. For reading a whole line at a time BufferedReader is chained to an InputStreamReader that in turn is chained to System.in. For example: This program read line from a file “students” and displays it on screen.

import java.io.*;
import java.util.*;
public class stud
{
public static void main (String args[ ]) throws IOException
{
BufferedReader br= new BufferedReader(new InputStreamReader(newFileInputStream(“students”)));
String s= “”;
while ((s= br.readLine())!=null) System.out.println(s);
}
catch (IOException e)
{
System.out.println(e);
}
}

Download Java Technical PDF Read All 10 Java Technical Questions
Previous QuestionNext Question
Explain different Authentication Options available in Servets?Tell me how to send data from my Java program to a CGI program?