Java OutputStream Write copyBytesToFile(byte[] bytes, File outputFile)

Here you can find the source of copyBytesToFile(byte[] bytes, File outputFile)

Description

copy Bytes To File

License

Open Source License

Declaration

public static File copyBytesToFile(byte[] bytes, File outputFile) throws Exception 

Method Source Code

//package com.java2s;
/**// ww  w . j  a v a 2 s . c om
 * License: https://github.com/votingsystem/votingsystem/wiki/Licencia
 */

import java.io.*;

public class Main {
    private static final int BUFFER_SIZE = 4096;

    public static File copyBytesToFile(byte[] bytes, File outputFile) throws Exception {
        InputStream inputStream = new ByteArrayInputStream(bytes);
        OutputStream outputStream = new FileOutputStream(outputFile);
        byte[] buf = new byte[BUFFER_SIZE];
        int len;
        while ((len = inputStream.read(buf)) > 0) {
            outputStream.write(buf, 0, len);
        }
        outputStream.close();
        inputStream.close();
        return outputFile;
    }
}

Related

  1. copyBytes(InputStream inputStream, OutputStream outputStream, int size)
  2. copyBytes(InputStream is, DataOutputStream[] os, long numBytes)
  3. copyBytes(InputStream is, OutputStream bytes)
  4. copyBytes(InputStream iStream, OutputStream oStream)
  5. copyBytesAndClose(final InputStream is, final OutputStream os)
  6. copyBytesToStream(ByteArrayOutputStream from, OutputStream to)
  7. copyBytesToStream(InputStream inputStream, OutputStream outputStream, int length)
  8. copyFile(File fromFile, File toFile)
  9. copyFile(final InputStream in, final OutputStream out, final int size)