Java FileOutputStream Write saveToFile(File file, byte[] buffer)

Here you can find the source of saveToFile(File file, byte[] buffer)

Description

Saves an array of bytes to a file in the file system.

License

Open Source License

Parameter

Parameter Description
file the Java file object where the bytes will be stored.
buffer the array of bytes.

Declaration

public static void saveToFile(File file, byte[] buffer) throws IOException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2013-2015 UAH Space Research Group.
 * 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.j a va 2  s. c  o  m
 *     MICOBS SRG Team - Initial API and implementation
 ******************************************************************************/

import java.io.File;

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

public class Main {
    /**
     * Saves an array of bytes to a file in the file system.
     * 
     * If an error occurs when storing the data, the method
     * will throw an {@link IOException}.
     * 
     * @param file the Java file object where the bytes will be 
     * stored.
     * @param buffer the array of bytes.
     */
    public static void saveToFile(File file, byte[] buffer) throws IOException {
        FileOutputStream out = new FileOutputStream(file);
        try {
            out.write(buffer);
        } finally {
            out.close();
        }

    }
}

Related

  1. saveToDisc(final InputStream fileInputStream, final String fileUploadPath)
  2. saveToDisk(InputStream is, String filename)
  3. saveToDisk(String contents, String filename)
  4. saveToEml(Message mail, File emlFile)
  5. saveToFile(byte[] data, String filename)
  6. saveToFile(final String file, final byte[] data, final boolean overwrite)
  7. saveToFile(final String text, final File file)
  8. saveToFile(InputStream in, File dst)
  9. saveToFile(InputStream in, String fileName)