Here you can find the source of saveToFile(final String text, final File file)
public static void saveToFile(final String text, final File file) throws 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:/*w w w . ja v a 2 s. co m*/ * eBay Inc. - initial API and implementation *******************************************************************************/ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; public class Main { public static final String ENCODING = "UTF-8"; public static void saveToFile(final String text, final File file) throws IOException { final FileOutputStream os = new FileOutputStream(file); try { os.write(text.getBytes(ENCODING)); os.flush(); } finally { os.close(); } } }