Name

Writer

Synopsis

This abstract class is the superclass of all character output streams. It is an analog to OutputStream, which is the superclass of all byte output streams. Writer defines the basic write( ) , flush( ), and close( ) methods all character output streams provide. The five versions of the write( ) method write a single character, a character array or subarray, or a string or substring to the destination of the stream. The most general version of this method—the one that writes a specified portion of a character array—is abstract and must be implemented by all subclasses. By default, the other write( ) methods are implemented in terms of this abstract one. The flush( ) method is another abstract method all subclasses must implement. It should force any output buffered by the stream to be written to its destination. If that destination is itself a character or byte output stream, it should invoke the flush( ) method of the destination stream as well. The close( ) method is also abstract. A subclass must implement this method so that it flushes and then closes the current stream and also closes whatever destination stream it is connected to. Once the stream is closed, any future calls to write( ) or flush( ) should throw an IOException.

In Java 5.0, this class has been modified to implement the Closeable and Flushable interfaces. It has also changed to implement java.lang.Appendable, which means that any Writer object can be used as the destination for a java.util.Formatter ...

Get Java in a Nutshell, 5th Edition 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.