CharArrayWriter: writeTo(Writer out)

 
import java.io.CharArrayWriter;
import java.io.FileWriter;
import java.io.IOException;

public class Main {
  public static void main(String args[]) throws IOException {
    CharArrayWriter f = new CharArrayWriter();
    String s = "This should end up in the array";
    char buf[] = new char[s.length()];
    s.getChars(0, s.length(), buf, 0);
    f.write(buf);
    System.out.println(f.toString());

    char c[] = f.toCharArray();
    for (int i = 0; i < c.length; i++) {
      System.out.print(c[i]);
    }

    FileWriter f2 = new FileWriter("test.txt");
    f.writeTo(f2);
    f2.close();
    f.reset();
    for (int i = 0; i < 3; i++)
      f.write('X');
  }
}
  
Home 
  Java Book 
    File Stream  

CharArrayWriter:
  1. CharArrayWriter
  2. CharArrayWriter: reset()
  3. CharArrayWriter: size()
  4. CharArrayWriter: toCharArray()
  5. CharArrayWriter: toString()
  6. CharArrayWriter: write(int c)
  7. CharArrayWriter: writeTo(Writer out)