Java tutorial
import java.io.CharArrayWriter; public class Main { public static void main(String[] args) throws Exception { String str = "from java2s.com!"; CharArrayWriter chw = new CharArrayWriter(); // create destination character array writer CharArrayWriter chwd = new CharArrayWriter(); chw.write(str); chw.writeTo(chwd); // print the destination buffer content as string System.out.println(chwd.toString()); System.out.println(chwd.size()); } }