Here you can find the source of writeStringToFile(String str, File file)
public static void writeStringToFile(String str, File file)
//package com.java2s; //License from project: LGPL import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; public class Main { public static void writeStringToFile(String str, File file) { BufferedWriter writer = null; try {// w w w. j ava 2 s. c o m file.delete(); file.createNewFile(); writer = new BufferedWriter(new FileWriter(file)); writer.write(str); } catch (IOException e) { e.printStackTrace(); } finally { try { if (writer != null) writer.close(); } catch (IOException e) { e.printStackTrace(); } } } }