Five times.
You don't have to have five statements using readLine();
a loop can be used to execute it the required number of times.
Here is a program that reads and echos the first five lines of
a file:
import java.io.*;
class MultiEcho
{
public static void main ( String[] args ) throws IOException
{
String line;
BufferedReader stdin = new BufferedReader(
new InputStreamReader( System.in ) );
int count = 1;
while ( count <= 5 )
{
System.out.println("Enter line" + count + ": ");
line = stdin.readLine();
System.out.println( "You typed: " + line );
count = count + 1;
}
}
}
Here is the program working with an input file:
C:\users\default\JavaLessons>java MultiEcho < input.txt Enter line1: You typed: This is line one, Enter line2: You typed: this is line two, Enter line3: You typed: this is line three, Enter line4: You typed: this is line, uh... four, Enter line5: You typed: and this is the last line. D:\users\default\JavaLessons>