Java File Append Text appendToFile(final File file, final String contents)

Here you can find the source of appendToFile(final File file, final String contents)

Description

Appends the contents String to a file.

License

Open Source License

Parameter

Parameter Description
file the file to save to.
contents String to append to file.

Declaration

public static void appendToFile(final File file, final String contents) throws IOException 

Method Source Code

//package com.java2s;

import java.io.File;

import java.io.FileOutputStream;

import java.io.IOException;

public class Main {
    /**//from   w  w  w. j a v a  2 s .  c om
     * Appends the contents String to a file.
     *
     * @param file the file to save to.
     * @param contents String to append to file.
     * @exception IOException if there is an error opening or writing to file.
     */
    public static void appendToFile(final File file, final String contents) throws IOException {
        try (FileOutputStream fos = new FileOutputStream(file, true)) {
            fos.write(contents.getBytes());
        }
    }
}

Related

  1. AppendTextToFile(String filePath, String text)
  2. appendTextToFile(String text, File file)
  3. appendToFile(File destFile, InputStream source)
  4. appendToFile(File file, String data)
  5. appendToFile(File tempFile, String str)
  6. appendToFile(final String filePath, final String textToAppend)
  7. appendToFile(final String text, final String urlFile)
  8. appendToFile(float[] in, String filename)
  9. appendToFile(IFile file, String output)