Courseiva
Java I/O API and Securing ApplicationsmediumMultiple ChoiceObjective-mapped

1Z0-829 Java I/O API and Securing Applications Practice Question

A developer wants to copy all files from one directory to another, preserving file attributes (e.g., last modified time, permissions). Which NIO.2 method is most appropriate?

⚠ Common exam trap

Many exam-takers confuse `REPLACE_EXISTING` with attribute preservation, assuming that replacing the target file inherently copies all metadata, when in fact `COPY_ATTRIBUTES` must be explicitly specified to preserve attributes.

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.copy(source, target, COPY_ATTRIBUTES)

The `Files.copy(source, target, COPY_ATTRIBUTES)` method from the NIO.2 API copies the content of the file and, when the `COPY_ATTRIBUTES` option is specified, also preserves the file's metadata attributes such as last modified time, last access time, and permissions (where supported by the underlying file system). This option is specifically designed for copying with attribute preservation, making it the most appropriate choice for the developer's requirement.

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.copy(source, target, COPY_ATTRIBUTES)

    Why this is correct

    COPY_ATTRIBUTES ensures attributes are preserved during copy.

  • Files.copy(source, target, REPLACE_EXISTING)

    Why it's wrong here

    This replaces the target but does not preserve attributes.

  • Files.move(source, target, ATOMIC_MOVE)

    Why it's wrong here

    Move operation does not necessarily preserve all attributes and is not a copy.

  • Files.walkFileTree() with a custom FileVisitor that copies files

    Why it's wrong here

    Possible but not the simplest one-step method for copying with attributes.

About these practice questions

Courseiva writes every 1Z0-829 question from scratch — 513 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

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.