Here you can find the source of appendFile(File targetFile, String toWrite)
public static void appendFile(File targetFile, String toWrite) throws Exception
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { /**//from ww w . j a va 2s . co m * Opens a file (targetFile) and appends a String (toWrite) to it */ public static void appendFile(File targetFile, String toWrite) throws Exception { if (!targetFile.exists()) { if (!targetFile.createNewFile()) throw new Exception("File was not created!"); } if (!targetFile.canWrite()) throw new Exception("No permission to write file!"); else { try { // WE CAN WRITE TO THE FILE FileWriter fw = new FileWriter(targetFile, true); fw.write(toWrite); fw.close(); } catch (Exception e) { throw e; } } } /** * Appends a String to a given file * * @param fileName The absolute path to the file to be written * @param toWrite The String to write to the file */ public static final void appendFile(String fileName, String toWrite) throws Exception { appendFile(new File(fileName), toWrite); } }