1Z0-829 Java I/O API and Securing Applications Practice Question
A Java application needs to refer to a file using the path "data/input.txt". To ensure platform independence (correct file separator), which approach is recommended?
⚠ Common exam trap
Many candidates think `new File("data/input.txt").toPath()` is sufficient, but it fails platform independence because the string literal contains a hardcoded forward slash, which is not the correct separator on Windows.
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
✓
Paths.get("data", "input.txt")
`Paths.get("data", "input.txt")` uses the default file system's path separator, ensuring platform independence. This method internally calls `FileSystems.getDefault().getPath()` to construct the path with the correct separator for the operating system (e.g., '/' on Linux/macOS, '\' on Windows).
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
FileSystems.getDefault().getPath("data", "input.txt")
Why it's wrong here
Equivalent to D (Paths.get()) but unnecessarily verbose; not recommended.
- ✗
new File("data/input.txt").toPath().normalize()
Why it's wrong here
Uses a hardcoded forward slash, so it is not platform-independent; normalize() only removes redundant path elements.
- ✗
new File("data/input.txt").toPath()
Why it's wrong here
Uses a hardcoded forward slash, so it is not platform-independent.
- ✓
Paths.get("data", "input.txt")
Why this is correct
Correct. Paths.get() uses the default file system's path separator, ensuring platform independence.
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.