Here you can find the source of writeFile(File file, String content)
public static boolean writeFile(File file, String content)
//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 boolean writeFile(File file, String content) { if (!file.exists()) { try { file.createNewFile();//from w ww . j ava 2s.co m } catch (IOException e) { return false; } } FileWriter w = null; try { w = new FileWriter(file); BufferedWriter bw = new BufferedWriter(w); bw.write(content); bw.flush(); w.flush(); w.close(); return true; } catch (IOException e) { if (w != null) { try { w.close(); } catch (IOException e2) { e.printStackTrace(); } } return false; } } }