The given example will test your understanding about the BufferedReader and FileReader classes and how to use this classes to read a file in Java.
The given example will test your understanding about the BufferedReader and FileReader classes and how to use this classes to read a file in Java.Given a sample code for reading a specific line from file
import java.io.*;
public class ReadSpecificLine {
public static void main(String[] args) {
String line = "";
int lineNo;
try {
(1) Place code here fr = new FileReader("new.txt");
BufferedReader br = new (2) Place code here;
for (lineNo = 1; lineNo < 10; lineNo++) {
if (lineNo == 5) {
line = (3) Place code here;
} else
br.readLine();
}
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Line: " + line);
}
}
Select the sequence of code from the given sentences for proper execution of above code.
(X) FileReader
(Y) br.readLine()
(Z)
BufferedReader(fr)
Options:
(A) 1-X, 2-Y, 3-Z
(B) 1-X, 2-Z , 3-Y
(C) 1-Z, 2-X, 3-Y
(B)