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

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

Description

Saves binary data to a file.

License

Open Source License

Parameter

Parameter Description
bytes the binary data to be saved
file the destination file

Declaration

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

Method Source Code


//package com.java2s;
import java.io.IOException;
import java.io.File;

import java.io.OutputStream;
import java.io.FileOutputStream;

public class Main {
    /**// w  w  w  . j  a va  2  s .c o m
     * Saves binary data to a file.
     * 
     * @param bytes the binary data to be saved
     * @param file the destination file
     * @exception IOException if there is an I/O problem
     */
    public static void saveBytes(byte[] bytes, File file) throws IOException {
        OutputStream out = new FileOutputStream(file);

        try {
            out.write(bytes, 0, bytes.length);
            out.flush();
        } finally {
            out.close();
        }
    }
}

Related

  1. saveBase64strToFile(String base64Str, String filePath)
  2. saveBinaryFile(String fileName, byte[] buffer)
  3. saveByteArrayToFile(final File file, final byte[] array)
  4. saveByteFile(byte[] data, String filePath)
  5. saveBytes(byte[] b, File destFolder, String fileName, String suffix)
  6. saveBytes(File f, byte[] content)
  7. saveBytes(File file, byte[] bytes)
  8. saveBytes(String filename, byte[] byteData)
  9. saveBytes(String filename, byte[] bytes)