CharArrayWriter: reset() : CharArrayWriter « java.io « Java by API






CharArrayWriter: reset()

 

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');
  }
}

   
  








Related examples in the same category

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