Short answer
readAllLines and readString load the entire file into memory, which is simple but dangerous for large files (OOM risk), so they're fine only when you know the file is small.
Explanation
Files.lines() returns a lazy Stream<String> that reads on demand, so it scales to huge files — but it's backed by an open file handle, so you must use it in try-with-resources or the descriptor leaks. The general rule is stream large or unbounded inputs and only slurp small, known-size files.
Common mistakes
- Using readAllLines on multi-gigabyte files.
- Forgetting Files.lines must be closed (it holds the file open).