Java Write Byte Array to File writeFile(byte[] data, File file)

Here you can find the source of writeFile(byte[] data, File file)

Description

Writes data into the file

License

Open Source License

Exception

Parameter Description
IOException if an I/O error occurs.

Declaration

public static void writeFile(byte[] data, File file) throws IOException 

Method Source Code

//package com.java2s;
/*/*from   www. j a v  a2s.  co 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.File;
import java.io.IOException;

import java.io.OutputStream;

import java.io.FileOutputStream;

public class Main {
    /**
     * Writes data into the file
     *
     * @throws IOException if an I/O error occurs.
     */
    public static void writeFile(byte[] data, File file) throws IOException {
        writeStream(data, new FileOutputStream(file));
    }

    /**
     * Writes data into the file
     *
     * @throws IOException if an I/O error occurs.
     */
    public static void writeFile(byte[] data, String file) throws IOException {
        writeStream(data, new FileOutputStream(file));
    }

    /**
     * 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. writeFile(byte[] bytes, File file)
  2. writeFile(byte[] bytes, File file)
  3. writeFile(byte[] bytes, String path)
  4. writeFile(byte[] content, String filename)
  5. writeFile(byte[] content, String filename)
  6. writeFile(byte[] data, File outFile)
  7. writeFile(byte[] data, String fileName)
  8. writeFile(byte[] data, String filePath)
  9. writeFile(byte[] data, String path, boolean overwrite)