Java File Append Text appendTextToFile(String file, String text)

Here you can find the source of appendTextToFile(String file, String text)

Description

Simple method to append text to a file

License

Open Source License

Parameter

Parameter Description
file The filename (with full path) to write to
text Text to appendto the file

Declaration

public static final void appendTextToFile(String file, String text) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.BufferedWriter;

import java.io.FileWriter;

import java.io.IOException;
import java.io.PrintWriter;

public class Main {
    /**/*from w  w w  .  ja v  a  2 s.c om*/
     * Simple method to append text to a file
     * @param file The filename (with full path) to write to
     * @param text Text to appendto the file
     */
    public static final void appendTextToFile(String file, String text) {
        try {
            PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(file, true)));
            out.print(text);
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Related

  1. appendText(String out, String text)
  2. appendText(String path, String text)
  3. appendTextString(File outputFile, String doc)
  4. appendTextToFile(@Nonnull File target, String text)
  5. appendTextToFile(File fileToAppend, Set linesToAppend)
  6. appendTextToFile(String file_name, String text)
  7. appendTextToFile(String filename, String data)
  8. AppendTextToFile(String filePath, String text)
  9. appendTextToFile(String text, File file)