โ† All 1Z0-819 Flashcard Decks

I/O Operations Flashcards

7 cards from real 1Z0-819 practice questions. Tap to flip, then mark Knew It or Still Learning โ€” missed cards come back until you master them.

Read the first 7 I/O Operations flashcards as text
  1. Which method in the `Files` class copies a file and replaces the destination if it already exists?

    Answer: Files.copy(src, dst, StandardCopyOption.REPLACE_EXISTING)

    `Files.copy` with `StandardCopyOption.REPLACE_EXISTING` overwrites the destination file if it exists.

  2. What does `Files.walk(path)` return?

    Answer: A `Stream` of all files in the directory tree

    `Files.walk` returns a lazy `Stream` that traverses the directory tree depth-first.

  3. Which `OpenOption` must be specified to append to an existing file using `Files.newOutputStream`?

    Answer: StandardOpenOption.APPEND

    `StandardOpenOption.APPEND` positions the stream at the end of the file before each write.

  4. What exception is thrown when you call `Files.readAllBytes` on a path that does not exist?

    Answer: NoSuchFileException

    `Files.readAllBytes` throws `NoSuchFileException` (a subclass of `IOException`) when the file is absent.

  5. What is the result of `Path.relativize(other)` when `other` is not relative to the base path?

    Answer: It may include `..` segments to navigate up the tree

    `relativize` uses `..` components to express a path from base to target even when traversal above base is needed.

  6. Which class provides buffered character-based reading with a `readLine()` method?

    Answer: BufferedReader

    `BufferedReader` wraps a `Reader` and offers the `readLine()` convenience method.

  7. When using `try-with-resources` with multiple `AutoCloseable` resources, in what order are they closed?

    Answer: Reverse order of declaration

    Resources are closed in the reverse order they are declared, ensuring proper cleanup of dependent resources.