Java Technical Question:
Download Questions PDF

read a line of input at a time in Java?

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 Interview Questions And Answers PDF

Previous QuestionNext Question
Explain different Authentication Options available in Servets?Tell me how to send data from my Java program to a CGI program?