Java FileOutputStream Write save(File file, byte[] bytes)

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

Description

Saves a byte array to a file.

License

Open Source License

Parameter

Parameter Description
file the file
bytes the byte array

Exception

Parameter Description
IOException an exception

Declaration

public static void save(File file, byte[] bytes) throws IOException 

Method Source Code

//package com.java2s;

import java.io.BufferedOutputStream;

import java.io.File;

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

import java.io.OutputStream;

public class Main {
    /**/*from   w  ww.j  a  va 2 s.c o m*/
     * Saves a byte array to a file.
     * 
     * @param file
     *            the file
     * @param bytes
     *            the byte array
     * @throws IOException
     */
    public static void save(File file, byte[] bytes) throws IOException {
        OutputStream os = new FileOutputStream(file);
        try {
            os = new BufferedOutputStream(os);
            for (int i = 0; i < bytes.length; i += 2048) {
                int len = Math.min(bytes.length - i, 2048);
                os.write(bytes, i, len);
            }
        } finally {
            os.close();
        }
    }
}

Related

  1. copyFileUsingFileStreams(InputStream source, File dest)
  2. copyFileUsingStream(InputStream sourceStream, File dest)
  3. save(byte[] bs, String fn)
  4. save(byte[] bytes, File path)
  5. save(byte[] data, String path)
  6. save(File file, byte[] content)
  7. save(File file, byte[] content)
  8. save(File file, final byte[] encoded)
  9. save(final InputStream in, final File file)