1Z0-829 Java I/O API and Securing Applications Practice Question
Which two of the following are valid methods to create a new directory using the NIO.2 Files class? (Select two.)
⚠ Common exam trap
A common mix-up: candidates confuse legacy java.io.File methods (mkdir, mkdirs) with NIO.2 Files methods, or misremember method names like createNewDirectory or makeDirectory, which do not exist in the Files class.
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
✓
Files.createDirectory(Path)
The Files class in the java.nio.file package provides two static methods for creating directories: createDirectory(Path) creates a single directory, failing if the parent does not exist or if the directory already exists; createDirectories(Path) creates the directory and any nonexistent parent directories, succeeding silently if the target already exists. Both are valid and commonly used for NIO.2 directory creation.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Files.mkdir(Path)
Why it's wrong here
No such method; mkdir is in File class.
- ✗
Files.createNewDirectory(Path)
Why it's wrong here
No such method in Files class.
- ✓
Files.createDirectory(Path)
Why this is correct
Creates a single directory if parent exists.
- ✓
Files.createDirectories(Path)
Why this is correct
Creates directories including all necessary parent directories.
- ✗
Files.makeDirectory(Path)
Why it's wrong here
No such method.
Go deeper
Related to this question
About these practice questions
This 1Z0-829 question is part of Courseiva's 513-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. 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.