Java Write Byte Array to File writeFile(String fileName, byte[] bytes)

Here you can find the source of writeFile(String fileName, byte[] bytes)

Description

write File

License

Apache License

Declaration

public static void writeFile(String fileName, byte[] bytes) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.BufferedOutputStream;
import java.io.File;

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

import java.io.OutputStream;

public class Main {
    public static void writeFile(String fileName, byte[] bytes) throws IOException {
        File f = new File(fileName);
        if (!f.exists()) {
            f.createNewFile();/*from   ww  w .  j a v  a  2  s .co  m*/
        } else {
            f.delete();
            f.createNewFile();
        }
        OutputStream os = new FileOutputStream(f);
        BufferedOutputStream out = new BufferedOutputStream(os);
        out.write(bytes);
        out.close();
        os.close();
        f = null;
    }
}

Related

  1. writeFile(File file, byte[]... data)
  2. writeFile(final File file, byte[] data)
  3. writeFile(String filename, byte data[])
  4. writeFile(String filename, byte[] bs)
  5. writeFile(String fileName, byte[] bytes)
  6. writeFile(String fileName, byte[] bytes)
  7. writeFile(String fileName, byte[] data)