Here you can find the source of writeStringToFile(String filename, String contents, Charset encoding)
public static void writeStringToFile(String filename, String contents, Charset encoding) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.Writer; import java.nio.charset.Charset; public class Main { public static void writeStringToFile(String filename, String contents, Charset encoding) throws IOException { try (Writer out = new OutputStreamWriter(new FileOutputStream(filename), encoding)) { out.write(contents);//from w w w. j a va 2 s.c o m } } public static void writeStringToFile(File file, String contents, Charset encoding) throws IOException { try (Writer out = new OutputStreamWriter(new FileOutputStream(file), encoding)) { out.write(contents); } } }