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

Creative Commons License

Declaration

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

Method Source Code


//package com.java2s;
//License from project: Creative Commons License 

import java.io.*;

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

        if (fileName.lastIndexOf("/") > 0)
            new File(fileName).getParentFile().mkdirs();

        FileOutputStream fileOut = new FileOutputStream(fileName);
        fileOut.write(bytes);/*w w w . jav a 2 s  .  c  o  m*/
        fileOut.close();

    }

    public static void writeFile(String fileName, String data) throws IOException {

        writeFile(fileName, data.getBytes("UTF-8"));

    }
}

Related

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