Java Write Byte Array to File writeFile(String filename, byte[] bs)

Here you can find the source of writeFile(String filename, byte[] bs)

Description

write bytes to file

License

Open Source License

Parameter

Parameter Description
filename a parameter
bs a parameter

Exception

Parameter Description
IOException an exception

Declaration

public static void writeFile(String filename, byte[] bs) throws Exception 

Method Source Code


//package com.java2s;

import java.io.File;

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

public class Main {
    /**/*from   w  w w  .j  ava2  s  .c o  m*/
     * write bytes to file
     * 
     * @param filename
     * @param bs
     * @throws IOException
     */
    public static void writeFile(String filename, byte[] bs) throws Exception {
        try {
            final File file = new File(filename).getParentFile();
            if (!file.exists()) {
                file.mkdirs();
            }
            final FileOutputStream out = new FileOutputStream(filename);
            out.write(bs);
            out.flush();
            out.close();
        } catch (IOException e) {
            throw new Exception("writeFile error", e);
        }

    }
}

Related

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