Here you can find the source of writeFile(final String aText, final File aFile, final String aEncoding)
protected static void writeFile(final String aText, final File aFile, final String aEncoding) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2009-2010 Richard Eckart de Castilho. * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Lesser Public License v2.1 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * * Contributors:/*from ww w .j av a 2s .c om*/ * Richard Eckart de Castilho - initial API and implementation ******************************************************************************/ import java.io.Closeable; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.Writer; public class Main { /** * For tests only. */ protected static void writeFile(final String aText, final File aFile, final String aEncoding) throws IOException { Writer writer = null; try { aFile.getParentFile().mkdirs(); writer = new OutputStreamWriter(new FileOutputStream(aFile), aEncoding); writer.write(aText); } finally { close(writer); } } /** * Close the given {@link Closeable}. * * @param aClosable a closable object. */ public static void close(final Closeable aClosable) { if (aClosable != null) { try { aClosable.close(); } catch (final IOException e) { // Ignore } } } }