Here you can find the source of writeFile(String fileName, String text, String characterEncoding)
public static void writeFile(String fileName, String text, String characterEncoding) throws UnsupportedEncodingException, FileNotFoundException, IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2012 eBay Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors://from w w w. j ava 2 s. co m * eBay Inc. - initial API and implementation *******************************************************************************/ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.UnsupportedEncodingException; public class Main { /** This will write a string to a file with the specified encoding */ public static void writeFile(String fileName, String text, String characterEncoding) throws UnsupportedEncodingException, FileNotFoundException, IOException { FileOutputStream fos; byte[] buf = text.getBytes(characterEncoding); int numWritten; fos = new FileOutputStream(fileName); numWritten = 0; fos.write(buf, numWritten, buf.length); fos.close(); } }