Java: When should a Java developer choose NIO Files and Path deliberately?

Difficulty:

Medium

Questions:

1

Time Limit:

2 minutes

Passing Score:

100%

Question

When should a Java developer choose NIO Files and Path deliberately?

  1. Use Files for reading, writing, walking directories, and querying file metadata in modern Java code.
  2. Choose NIO Files and Path mainly when you want to postpone validation and fix problems manually later.
  3. Choose NIO Files and Path whenever you want the code to look more advanced, even if the design gets less clear.
  4. Choose NIO Files and Path only to avoid modeling domain rules explicitly in Java code.

Hint

Think about the production scenario where the choice genuinely improves the code.

Answer and rationale

Correct answer: A. Use Files for reading, writing, walking directories, and querying file metadata in modern Java code.

Use Files for reading, writing, walking directories, and querying file metadata in modern Java code. Interviewers often ask this to see whether you can connect the concept to real design decisions.

Track: Java