Here you can find the source of appendContent(File file, String content, String encoding)
Parameter | Description |
---|---|
filepath | File to be appended. |
content | String content to be appended to file. |
encoding | Encoding used for string content. |
Parameter | Description |
---|---|
IOException | an exception |
public static void appendContent(File file, String content, String encoding) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.BufferedWriter; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.Writer; public class Main { /**/*from w w w. jav a2 s. com*/ * Append text content to file. * * @param filepath * Path to file * @param content * String content to be appended to file. * @throws IOException */ public static void appendContent(String filepath, String content) throws IOException { appendContent(new File(filepath), content); } /** * Append text content to file. * * @param filepath * File to be appended. * @param content * String content to be appended to file. * @throws IOException */ public static void appendContent(File file, String content) throws IOException { appendContent(file, content, "UTF-8"); } /** * Append text content to file, with encoding. * * @param filepath * Path to file * @param content * String content to be appended to file. * @param encoding * Encoding used for string content. * * @throws IOException */ public static void appendContent(String filepath, String content, String encoding) throws IOException { appendContent(new File(filepath), content, encoding); } /** * Append text content to file, with encoding. * * @param filepath * File to be appended. * @param content * String content to be appended to file. * @param encoding * Encoding used for string content. * * @throws IOException */ public static void appendContent(File file, String content, String encoding) throws IOException { Writer writer = null; try { writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, true), encoding)); writer.append(content); } finally { if (writer != null) { writer.flush(); writer.close(); } } } }