Files.newBufferedWriter() takes a Path object, but incorrectly passed a File object · Issue #271 · java/devjava-content
Repository navigation
Files.newBufferedWriter() takes a Path object, but incorrectly passed a File object #271
New issue
New issue
Open
Open
Files.newBufferedWriter() takes a Path object, but incorrectly passed a File object #271
Description
@authentictech's profile authentictech opened on Aug 13, 2026In Tutorials > The Java I/O API > File Operations Basics > Releasing Resources and Catching Exceptions, "Catching Exceptions " section, the sample code creates a File object and passes it into Files.newBufferedWriter().
However, according to the Java Docs, this method takes a java.nio.file.Path object, not a java.io.File object.
Charset charset = Charset.forName("US-ASCII");
File file = ...;
String s = ...;
try (BufferedWriter writer = Files.newBufferedWriter(file, charset)) {
writer.write(s, 0, s.length());
} catch (IOException x) {
System.err.format("IOException: %s%n", x);
}