Oracle
1Z0-819 · Question #78
1Z0-819 Question #78: Real Exam Question with Answer & Explanation
Sign in or unlock 1Z0-819 to reveal the answer and full explanation for question #78. The question stem and answer options stay visible for context.
Question
Given:
List<Reader> dataFiles = new ArrayList<>();
dataFiles.add(new FileReader("MyIndex.idx"));
File indexReaderFile = new FileReader(indexFile);
try (BufferedReader indexReader = new BufferedReader(
new FileReader(new File(indexFile))){
for(int file = indexReader.read(); file != null;
file = indexReader.readLine()){
BufferedReader dataReader = new BufferedReader (
new FileReader(new File(file))); // Line 1
dataFiles.add(dataReader); // Line 2
processData(dataReader); // Line 3
}
} catch (IOException ex) {
}
finally {
for(Reader r : dataFiles) {
try {
r.close();
} catch (IOException ex) {
}
} // Line 4
}
What will secure this code from a potential Denial of Service condition?
Options
- AAfter Line 4, add indexReader.close().
- BOn Line 1, enclose new BufferedReader(new FileReader) with try with resources. After Line 3, add dataReader.close().
- COn Line 1, use try with resources when opening each dataReader. Before Line 1, check the size of dataFiles to make sure it does not exceed a threshold.
Unlock 1Z0-819 to see the answer
You've previewed enough free 1Z0-819 questions. Unlock 1Z0-819 for full answers, explanations, the timed quiz mode, progress tracking, and the master PDF. Question stem and options stay visible so you can still see what's on the exam.