Default-charset file I/O to explicit StandardCharsets
Use Files readers and writers with StandardCharsets constants instead of platform-default charset behavior and charset-name lookup.
try (Reader reader = new FileReader(path.toFile())) {
return readAll(reader);
}
try (BufferedReader reader = Files.newBufferedReader(
path, StandardCharsets.UTF_8)) {
return readAll(reader);
}
Portable results
The same bytes decode identically on every machine.
Predefined constant
StandardCharsets.UTF_8 cannot contain a misspelled charset name.
Modern file API
Path, buffering, and encoding are expressed in one operation.
Widely available since JDK 7 (July 2011)
Reader and writer constructors that rely on the default charset make file behavior depend on the runtime environment. Files.newBufferedReader() and newBufferedWriter() accept an explicit Charset, while StandardCharsets provides guaranteed constants such as UTF_8 without string lookup or UnsupportedCharsetException. This combines the explicit-file-encoding and Charset.forName("UTF-8") migrations into one coherent pattern.