ProLesson 11.2Intermediate3 min readUpdated 30 October 2026
Reading and writing text files
Read and write text correctly with buffered readers and writers, always choose UTF-8, and process a CSV file line by line.
Most real file work is text: CSV exports, logs, configuration, reports. This lesson covers the right tools for each file size, and the encoding detail that silently breaks many programs.
01Small files: one line of code
java
String content = Files.readString(path); // whole file → String (UTF-8)
Files.writeString(path, "hello\n"); // String → file (UTF-8)
List<String> lines = Files.readAllLines(path); // every line in a ListThese are perfect for configuration and small files, up to a few megabytes.
Loading the rest of the lesson…