Here you can find the source of writeAllText(File file, String contents)
public static void writeAllText(File file, String contents) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2013, 2014 ETAS GmbH./* w w w . j a v a 2 s. c o m*/ * 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: * Dennis Eder (ETAS GmbH) - initial API and implementation and/or initial documentation *******************************************************************************/ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; public class Main { final static Charset ENCODING = StandardCharsets.UTF_8; public static void writeAllText(File file, String contents) throws IOException { FileOutputStream fos = new FileOutputStream(file); OutputStreamWriter out = new OutputStreamWriter(fos, ENCODING); out.write(contents); out.close(); } }