Java CharArrayWriter writeTo() Example
CharArrayWriter class writeTo() method example. This example shows you how to use writeTo() method.
Syntax is : public void writeTo() throws IOException
This method writes the contents of the buffer to another character stream.
Here is the code.
/**
* @(#) WriteToCharArrayWriter.java
* A class representing use of method writeTo() of CharArrayWriter() class
in java.io Package.
* @Version 03-May-2008
* @author Rose India Team
*/
import java.io.*;
public class WriteToCharArrayWriter {
public static void main(String[] args) throws IOException{
// create object of StringWriter class to hold elements of the buffer.
StringWriter strWriterObj = new StringWriter();
// Create object of CharArrayWriter class.
CharArrayWriter objCharArrWriter = new CharArrayWriter();
objCharArrWriter.append("Mahendra");
System.out.println("Character buffer is : " + objCharArrWriter);
// writeTo() method call.
objCharArrWriter.writeTo(strWriterObj);
System.out.print("The contents of the buffer has successfully written "
+"to another character stream.\n");
System.out.print("New character stream is : " + strWriterObj);
}
} |
Output of the program.
Character buffer is : Mahendra
The contents of the buffer has successfully written to another character stream.
New character stream is : Mahendra |
|