Here you can find the source of writeStringToFile(String str, File file)
public static void writeStringToFile(String str, File file) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2004, 2007 Boeing./*from w w w . j a v a 2 s . com*/ * 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: * Boeing - initial API and implementation *******************************************************************************/ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; public class Main { public static void writeStringToFile(String str, File file) throws IOException { OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(file), "UTF-8"); char[] chars = str.toCharArray(); out.write(chars, 0, chars.length); out.close(); } }