Name
CharArrayWriter
Synopsis
This
class is a character output stream that uses an internal character
array as the destination of characters written to it. When you create
a CharArrayWriter
, you may optionally specify an
initial size for the character array, but you do not specify the
character array itself; this array is managed internally by the
CharArrayWriter
and grows as necessary to
accommodate all the characters written to it. The toString(
)
and toCharArray( )
methods return a copy of all
characters written to the stream, as a string and an array of
characters, respectively. CharArrayWriter
defines
the standard write( )
,
flush( )
, and close( )
methods
all Writer
subclasses define. It also defines a
few other useful methods. size(
)
returns the number of characters that
have been written to the stream. reset( )
resets
the stream to its initial state, with an empty character array; this
is more efficient than creating a new
CharArrayWriter
. Finally, writeTo(
)
writes the contents of the
internal character array to some other specified character stream.
CharArrayWriter
is the character-stream analog of
ByteArrayOutputStream
and is quite similar to
StringWriter
.
Figure 9-8. java.io.CharArrayWriter
public class CharArrayWriter extends Writer { // Public Constructors public CharArrayWriter( ); public CharArrayWriter(int initialSize); // Public Instance Methods 5.0 public CharArrayWriter ...
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.