Java CharArrayWriter write to file
import java.io.CharArrayWriter; import java.io.FileWriter; import java.io.IOException; public class Main { public static void main(String args[]) throws IOException { String s = "test from demo2s.com"; char buf[] = new char[s.length()]; s.getChars(0, s.length(), buf, 0);/*from w ww .j a va2s . c o m*/ CharArrayWriter f = new CharArrayWriter(); f.write(buf); System.out.println(f.toString()); FileWriter f2 = new FileWriter("Main.txt"); f.writeTo(f2); f2.close(); } }