1Z0-829 Java I/O API and Securing Applications Practice Question
A Java application reads configuration from a file using FileInputStream. The application must handle the case where the configuration file is missing by logging a warning and using default values. Which design approach best meets this requirement?
⚠ Common exam trap
It's easy for candidates to confuse `File.exists()` (legacy, less reliable) with `Files.exists()` (modern, recommended), and they may incorrectly assume that catching `FileNotFoundException` is the standard way to handle missing files, overlooking the cleaner pre-check approach that avoids exceptions entirely.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Use Files.exists() to check file existence before opening the stream, and if absent, log a warning and use defaults.
It explicitly checks for file existence using `Files.exists()` before attempting to open the stream, allowing the application to log a warning and fall back to default values without throwing an exception. This approach aligns with the requirement to handle a missing configuration file gracefully, avoiding unnecessary exception handling overhead. The `Files.exists()` method is part of the modern `java.nio.file` API, which is preferred over the legacy `File.exists()` for its better integration with symbolic links and file system operations.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Wrap the FileInputStream in a try-with-resources and catch Exception to handle missing file.
Why it's wrong here
Catching Exception is too broad and may hide other issues.
- ✓
Use Files.exists() to check file existence before opening the stream, and if absent, log a warning and use defaults.
Why this is correct
Proactive check avoids exception overhead and is clear.
- ✗
Catch FileNotFoundException inside the try block and set default values.
Why it's wrong here
FileNotFoundException is specific, but it's better to check existence first.
- ✗
Use File.exists() to check file existence before opening the stream, and if absent, log a warning and use defaults.
Why it's wrong here
File.exists() is outdated; Files.exists() is preferred.
Go deeper
Related to this question
About these practice questions
One of 513 original 1Z0-829 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This 1Z0-829 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-829 exam.