Java Utililty Methods File Append

List of utility methods to do File Append

Description

The list of methods to do File Append are organized into topic(s).

Method

voidappendFile(File src, File dst)
append File
copyOrAppend(src, dst, true);
voidappendFile(File targetFile, String text)
Appends the given String to the end of a file.
BufferedWriter writer = new BufferedWriter(new FileWriter(targetFile));
writer.append(text);
writer.flush();
writer.close();
voidappendFile(File targetFile, String toWrite)
Opens a file (targetFile) and appends a String (toWrite) to it
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 {
...
voidappendFile(final File srcFile, final File destFile)
This method append the src file to dest file.
InputStream in = null;
in = new FileInputStream(srcFile);
final FileOutputStream out = new FileOutputStream(destFile, true);
final byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
    out.write(buf, 0, len);
if (in != null) {
    in.close();
if (out != null) {
    out.close();
voidappendFile(final String filename, final String content)
append File
FileOutputStream output = new FileOutputStream(filename, true);
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(output));
writer.write(content);
writer.close();
output.close();
voidappendFile(final String name, final String s)
Writes to the file with the given name
writeFile(name, s, true);
voidappendFile(OutputStream output, File source)
append File
InputStream input = null;
try {
    input = new BufferedInputStream(new FileInputStream(source));
    byte[] buf = new byte[1024];
    int len;
    while ((len = input.read(buf)) > 0) {
        output.write(buf, 0, len);
} finally {
    input.close();
voidappendFile(String content, File file)
append File
BufferedWriter writer = new BufferedWriter(new FileWriter(file, true));
writer.write(content);
writer.newLine();
writer.close();
voidappendFile(String file, byte[]... data)
append File
try (FileOutputStream fos = new FileOutputStream(file, true)) {
    for (byte[] d : data) {
        fos.write(d);
} catch (IOException ex) {
voidappendFile(String file, String content)
Append 'content' in 'dir'/'file'
try (PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(file, true)))) {
    out.println(content);
    out.close();
} catch (Exception e) {
    e.printStackTrace();