Write String to File with BufferWriter
import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
class Utils {
public static void writeToFile(String fileName, String text)
throws IOException {
BufferedWriter out = null;
try {
// XXX is it UTF8 or UTF-8 ???
out = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(fileName), "UTF8"));
out.write(text);
out.close();
} finally {
if (out != null) {
out.close();
}
}
}
}
Related examples in the same category