Here you can find the source of writeStringToFile(String string, File file)
public static File writeStringToFile(String string, File file) throws UnsupportedEncodingException, FileNotFoundException, IOException
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.UnsupportedEncodingException; public class Main { public static File writeStringToFile(String string, File file) throws UnsupportedEncodingException, FileNotFoundException, IOException { try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file), "UTF-8")) { writer.write(string);/*from w ww. j av a 2s . co m*/ } return file; } }