← Winnitude! Search  ·  Reader Mode (1508 ms)
Links: Stay in Reader Retro Site Converter Retro Mode: OFF Original Page ↗
GITHUB · 7 LINKS

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, 2026

In 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);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions