Here you can find the source of appendFile(File file, String content)
Parameter | Description |
---|---|
file | File where the text will be written |
content | Text to be written |
Parameter | Description |
---|---|
FileNotFoundException | If the file is a directory |
IOException | If an I/O error happend while writing |
public static void appendFile(File file, String content) throws FileNotFoundException, IOException
//package com.java2s; //License from project: Open Source License import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; public class Main { /**/* w w w.j av a2 s .c om*/ * Write some text into the end of a file (append) * @param file File where the text will be written * @param content Text to be written * @throws FileNotFoundException If the file is a directory * @throws IOException If an I/O error happend while writing */ public static void appendFile(File file, String content) throws FileNotFoundException, IOException { BufferedWriter bw = null; try { bw = new BufferedWriter(new FileWriter(file, true)); bw.write(content); bw.flush(); } catch (FileNotFoundException e) { if (bw != null) bw.close(); throw e; } finally { if (bw != null) bw.close(); } } }