Here you can find the source of writeFile(String filePath, String content, boolean append)
public static synchronized void writeFile(String filePath, String content, boolean append) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.BufferedWriter; import java.io.Closeable; import java.io.File; import java.io.FileWriter; import java.io.IOException; public class Main { public static synchronized void writeFile(String filePath, String content, boolean append) throws IOException { File file = new File(filePath); if (createFile(filePath)) { BufferedWriter bufferedWriter = null; try { FileWriter fileWriter = new FileWriter(file, append); bufferedWriter = new BufferedWriter(fileWriter); bufferedWriter.write(content); bufferedWriter.flush();//from ww w.ja v a2s .co m } finally { closeResource(bufferedWriter); } } } public static synchronized void writeFile(String filePath, String content) throws IOException { writeFile(filePath, content, false); } public static synchronized boolean createFile(String filePath) throws IOException { File file = new File(filePath); File folder = file.getParentFile(); boolean folderCreated = folder.exists() || folder.mkdirs(); boolean fileCreated = file.exists() || file.createNewFile(); return folderCreated && fileCreated; } public static void closeResource(Closeable closeable) { if (closeable != null) { try { closeable.close(); } catch (IOException e) { // ignore } } } }