Share on Google+Share on Google+

SCJP Module-10 Question-10

Ads
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

Answer:

(B)

Advertisements

Ads

Posted on: July 17, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Ads

Advertisement