Java FileOutputStream Write Byte Array writeBytesToFile(String strFilePath, byte[] fileData)

Here you can find the source of writeBytesToFile(String strFilePath, byte[] fileData)

Description

write Bytes To File

License

Apache License

Declaration

public static void writeBytesToFile(String strFilePath, byte[] fileData) 

Method Source Code

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

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

public class Main {
    public static void writeBytesToFile(String strFilePath, byte[] fileData) {
        try {//w w  w. j  a  v  a 2s.co m
            FileOutputStream fos = new FileOutputStream(strFilePath);

            /*
            * To write byte array to a file, use
            * void write(byte[] bArray) method of Java FileOutputStream class.
            *
            * This method writes given byte array to a file.
            */

            fos.write(fileData);

            /*
            * Close FileOutputStream using,
            * void close() method of Java FileOutputStream class.
            *
            */

            fos.close();
        } catch (FileNotFoundException ex) {
            System.out.println("FileNotFoundException : " + ex);
        } catch (IOException ioe) {
            System.out.println("IOException : " + ioe);
        }

    }
}

Related

  1. writeBytesToFile(File file, byte[] bytes)
  2. writeBytesToFile(File theFile, byte[] bytes)
  3. writeBytesToFile(final byte[] data, String filename)
  4. writeBytesToFile(List bytes, File file)
  5. writeBytesToFile(String filename, byte[] data)
  6. writeBytesToFilename(String filename, byte[] bytes)