Java File Append LIne AppendLineToFile(String filePath, String text)

Here you can find the source of AppendLineToFile(String filePath, String text)

Description

Appends a line to an existing file (incuding a new line character).

License

Open Source License

Parameter

Parameter Description
filePath Absolute file path
text Text to append

Exception

Parameter Description
Exception an exception

Declaration

public static void AppendLineToFile(String filePath, String text) throws Exception 

Method Source Code


//package com.java2s;
// it under the terms of the GNU General Public License as published by

import java.io.*;

public class Main {
    /** Appends a line to an existing file (incuding a new line character).
     *//www. j a  v a  2  s .c  o  m
     * @param filePath Absolute file path
     * @param text Text to append
     * @throws Exception
     */
    public static void AppendLineToFile(String filePath, String text) throws Exception {
        AppendTextToFile(filePath, text + "\n");
    }

    /** Convenience method that appends text to an existing file.
     *
     * @param filePath Absolute file path
     * @param text Text to append
     * @throws Exception
     */
    public static void AppendTextToFile(String filePath, String text) throws Exception {
        PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(filePath, true)));
        out.write(text);
        out.close();
    }
}

Related

  1. appendLineInFile(String path, String lines)
  2. appendLines(File file, String[] lines)
  3. appendLines(File file, String[] lines)
  4. appendLinesToFile(Iterable lines, File outFile)
  5. appendLineToFile(String fileName, String format, Object... vals)
  6. appendLineToFile(String path, String line)
  7. appendLineToTextFile(File file, String line)