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

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

Description

write File

License

Open Source License

Declaration

public static void writeFile(File file, byte[] data) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;

import java.io.File;

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

public class Main {
    public static void writeFile(File file, byte[] data) throws IOException {
        ByteArrayInputStream bais = new ByteArrayInputStream(data);
        FileOutputStream fos = new FileOutputStream(file);
        BufferedOutputStream bos = new BufferedOutputStream(fos);
        byte[] buffer = new byte[1024];
        int br;/* w  w w .  j av a  2 s . c om*/
        while ((br = bais.read(buffer)) > 0) {
            bos.write(buffer, 0, br);
        }
        bos.close();
        bais.close();
    }
}

Related

  1. writeFile(File file, byte[] content)
  2. writeFile(File file, byte[] context, boolean append)
  3. writeFile(File file, byte[] data)
  4. writeFile(File file, byte[] data)
  5. writeFile(File file, byte[] data)
  6. writeFile(File file, byte[] data)
  7. writeFile(File file, byte[] data)
  8. writeFile(File file, byte[] data)
  9. writeFile(File file, byte[]... data)