BufferedWriter Class

Package: java.io

The BufferedWriter class connects to a FileWriter but adds output buffering.

In most cases, you won’t use methods of this class directly. Instead, you’ll use this class to connect to a PrintWriter, which has more useful methods for writing output data to a character stream. As a result, this section shows only the constructor for the BufferedWriter class and not its methods. For more information, see PrintWriter Class.

CrossRef.eps The BufferedWriterStream class is one of many Java I/O classes that use streams. For more information, see Streams (Overview).

Constructor

Constructor

Description

BufferedWriter (Writer out)

Creates a buffered reader from any object that extends the Writer class. Typically, you pass this constructor a FileWriter object.

The following example shows how to create a BufferedWriter object that connects to a text file:

File f;

FileWriter fwriter;

BufferedWriter bwriter;

f = new File(“myfile.txt”);

fwriter = new FileWriter(f);

bwriter = new BufferedWriter(fwriter);

Get Java For Dummies Quick Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.