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

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

Description

write File

License

Open Source License

Declaration

public static void writeFile(byte[] bytes, File file) 

Method Source Code

//package com.java2s;
/******************************************************************************
 * Copyright (c) 2012 Masatomi KINO 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://from w w  w. jav a 2 s.  c o  m
 *      Masatomi KINO - initial API and implementation
 * $Id$
 ******************************************************************************/

import java.io.BufferedOutputStream;

import java.io.File;

import java.io.FileOutputStream;
import java.io.IOException;

public class Main {
    public static void writeFile(byte[] bytes, File file) {
        BufferedOutputStream stream = null;
        try {
            FileOutputStream fstream = new FileOutputStream(file);
            stream = new BufferedOutputStream(fstream);
            stream.write(bytes);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (stream != null) {
                try {
                    stream.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }

        }
    }
}

Related

  1. writeFile(byte data[], File file)
  2. writeFile(byte[] b, String fileName)
  3. writeFile(byte[] buf, File file)
  4. writeFile(byte[] bytes, File file)
  5. writeFile(byte[] bytes, File file)
  6. writeFile(byte[] bytes, String path)
  7. writeFile(byte[] content, String filename)
  8. writeFile(byte[] content, String filename)
  9. writeFile(byte[] data, File file)