Java File Append appendFile(byte[] data, String file)

Here you can find the source of appendFile(byte[] data, String file)

Description

Appends data to the file

License

Open Source License

Exception

Parameter Description
IOException if an I/O error occurs.

Declaration

public static void appendFile(byte[] data, String file) throws IOException 

Method Source Code

//package com.java2s;
/*//from w  w  w. j  a  va  2  s  .  c  o m
* Copyright (c) 2000 - 2005 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:  
*
*/

import java.io.IOException;

import java.io.OutputStream;

import java.io.FileOutputStream;

public class Main {
    /**
     * Appends data to the file
     *
     * @throws IOException if an I/O error occurs.
     */
    public static void appendFile(byte[] data, String file) throws IOException {
        writeStream(data, new FileOutputStream(file, true));
    }

    /**
     * Writes data into the stream and closes the output stream
     *
     * @throws IOException if an I/O error occurs.
     */
    public static void writeStream(byte[] data, OutputStream out) throws IOException {
        try {
            out.write(data);
            out.flush();
        } finally {
            out.close();
        }
    }
}

Related

  1. appendContent(File file, String content, String encoding)
  2. appendContentsToFile(File file, StringBuilder contents)
  3. appendContentsTofile(String fileName, String contents)
  4. appendContentToFile(File file, String fileContent)
  5. appendFile(File f, String content)
  6. appendFile(File f, StringBuffer sb)
  7. appendFile(File file, String content)
  8. appendFile(File file, String url)