Here you can find the source of writeStringToFile(String str, File file)
public static File writeStringToFile(String str, File file)
//package com.java2s; //License from project: Apache License import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.PrintWriter; import java.io.StringReader; public class Main { public static File writeStringToFile(String str, File file) { try {/* w ww. j a v a2 s . c o m*/ BufferedReader in4 = new BufferedReader(new StringReader(str)); PrintWriter out1 = new PrintWriter(new BufferedWriter(new FileWriter(file))); String tempStr = null; while ((tempStr = in4.readLine()) != null) { out1.println(tempStr); } out1.close(); } catch (Exception e) { e.printStackTrace(); } return file; } }