Here you can find the source of writeTextFile(final File file, final String text)
public static void writeTextFile(final File file, final String text) throws Exception
//package com.java2s; /**/*w w w . j av a 2 s . c o m*/ * Copyright (C) 2010-2012 Andrei Pozolotin <Andrei.Pozolotin@gmail.com> * * All rights reserved. Licensed under the OSI BSD License. * * http://www.opensource.org/licenses/bsd-license.php */ import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.nio.charset.Charset; public class Main { private static final Charset UTF_8 = Charset.forName("UTF-8"); public static void writeTextFile(final File file, final String text) throws Exception { final OutputStream stream = new FileOutputStream(file); final BufferedOutputStream output = new BufferedOutputStream(stream); final OutputStreamWriter writer = new OutputStreamWriter(output, UTF_8); writer.write(text); writer.flush(); writer.close(); } }