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

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

A developer is writing a utility to copy a large binary file (e.g., 500 MB) from one location to another while minimizing memory overhead and ensuring data integrity. Which approach is most appropriate?

⚠ Common exam trap

It's easy for candidates to choose Files.copy() (Option C) because it is convenient and commonly used, but the question explicitly requires minimizing memory overhead, and Files.copy() does not expose buffer size control, making the custom loop (Option B) the more precise answer for this specific constraint.

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

Use a custom loop reading into a byte array of 8KB and writing to the output stream.

Reading and writing in fixed-size chunks (e.g., 8KB) minimizes memory overhead by avoiding loading the entire 500 MB file into memory, while still providing efficient I/O through buffered operations. This approach ensures data integrity by processing the file sequentially without relying on character-based streams, which are unsuitable for binary data.

Answer analysis

Option-by-option breakdown

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

  • Use BufferedReader and BufferedWriter for binary data.

    Why it's wrong here

    Character streams are unsuitable for binary data.

  • Use a custom loop reading into a byte array of 8KB and writing to the output stream.

    Why this is correct

    Processes data in small chunks, keeping memory usage low.

  • Use Files.copy() with StandardCopyOption.REPLACE_EXISTING.

    Why it's wrong here

    Files.copy() is efficient but may not be as memory-optimized as a custom loop; also it's not the most customizable.

  • Use FileInputStream.readAllBytes() and FileOutputStream.write().

    Why it's wrong here

    Loads the entire file into memory, causing high memory usage.

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.