Java File Append appendFileContent(File file, String content, boolean append)

Here you can find the source of appendFileContent(File file, String content, boolean append)

Description

Appends content to given file.

License

Open Source License

Parameter

Parameter Description
file a parameter
content a parameter
append if true, then bytes will be written to the end of the file rather than the beginning

Exception

Parameter Description
IOException an exception

Declaration

public static void appendFileContent(File file, String content, boolean append) throws IOException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2010, 2014 SAP AG and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*  w ww. ja v  a 2s.c om*/
 *    Mathias Kinzler (SAP AG) - initial implementation
 *******************************************************************************/

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;

public class Main {
    /**
     * Appends content to given file.
     *
     * @param file
     * @param content
     * @param append
     *            if true, then bytes will be written to the end of the file
     *            rather than the beginning
     * @throws IOException
     */
    public static void appendFileContent(File file, String content, boolean append) throws IOException {
        Writer fw = null;
        try {
            fw = new OutputStreamWriter(new FileOutputStream(file, append), "UTF-8");
            fw.append(content);
        } finally {
            if (fw != null)
                fw.close();
        }
    }
}

Related

  1. appendFile(String path, String content)
  2. appendFile(String path, String sb)
  3. appendFile(String source, String filetoappend)
  4. appendFile(String strThrift, String filePath)
  5. appendFileBytes(String srcFileName, String tarFileName)
  6. appendFileLines(String fileName, String[] data)
  7. appendFilePart(File dstFile, byte[] bytes)
  8. appendHex(A sb, byte[] array, int offset, int len, char sep)
  9. appendHexJavaScriptRepresentation(Appendable out, int codePoint)