โ† 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 `Files` method reads all lines of a text file into a `List` using the default charset?

    Answer: Files.readAllLines(path)

    `Files.readAllLines(path)` reads all lines into a `List` using UTF-8 by default in Java 11.

  2. What is the key difference between `Files.lines(path)` and `Files.readAllLines(path)`?

    Answer: `Files.lines` returns a lazy `Stream` while `readAllLines` loads everything into memory immediately

    `Files.lines` is lazy and streams lines on demand, whereas `readAllLines` materializes all lines into a `List` at once.

  3. Which method creates all missing parent directories for a given path in one call?

    Answer: Files.createDirectories(path)

    `Files.createDirectories` creates the target directory and all missing parents without throwing an error if they already exist.

  4. What does `Path.normalize()` do?

    Answer: Removes redundant `.` and `..` elements from the path

    `normalize()` eliminates redundant `.` (current directory) and `..` (parent directory) segments without accessing the filesystem.

  5. Which method on `Path` combines the current path with another path segment?

    Answer: resolve()

    `resolve()` appends the given path to the base path, handling absolute/relative combinations correctly.

  6. What does `Files.isSameFile(path1, path2)` check?

    Answer: Whether both paths locate the same file on the filesystem, even via different names or symlinks

    `Files.isSameFile` uses the OS to determine if both paths refer to the same inode/file, resolving symlinks.

  7. What happens when you call `Files.delete(path)` on a non-empty directory?

    Answer: It throws `DirectoryNotEmptyException`

    `Files.delete` will throw `DirectoryNotEmptyException` if the directory still contains entries.