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

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

A Java application writes sensitive user data to a file. To ensure that data is not left in the file system after the application crashes, which practice should be followed?

⚠ Common exam trap

A common mix-up: candidates confuse data flushing or locking with crash-safe file updates, but neither `flush()` nor `FileLock` provides atomicity guarantees, which is the key requirement for preventing data corruption after a crash.

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

Write to a temporary file, then use Files.move() with ATOMIC_MOVE to replace the target file

Writing to a temporary file and then atomically moving it with `Files.move()` using the `ATOMIC_MOVE` option ensures that the target file is replaced only after the write succeeds. If the application crashes during the write, only the temporary file is corrupted, and the original target file remains intact. This prevents sensitive data from being left in an incomplete or partially written state in the file system.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • Call flush() after every write operation

    Why it's wrong here

    Flush only ensures data is sent to the OS, but doesn't guarantee atomicity or cleanup on crash.

  • Delete the file manually in a finally block

    Why it's wrong here

    If the JVM crashes abruptly, the finally block may not execute, leaving the file.

  • Use a FileLock to prevent concurrent access

    Why it's wrong here

    FileLock prevents concurrent access but does not prevent data residue after a crash.

  • Write to a temporary file, then use Files.move() with ATOMIC_MOVE to replace the target file

    Why this is correct

    Atomic move ensures the target file is either fully written or not replaced, preventing partial writes.

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 →

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.