Java FileOutputStream Write Byte Array writeBytesToFile(byte[] bfile, String filePath, String fileName)

Here you can find the source of writeBytesToFile(byte[] bfile, String filePath, String fileName)

Description

write Bytes To File

License

Open Source License

Declaration

public static File writeBytesToFile(byte[] bfile, String filePath, String fileName) 

Method Source Code


//package com.java2s;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

public class Main {
    public static File writeBytesToFile(byte[] bfile, String filePath, String fileName) {
        BufferedOutputStream bos = null;
        FileOutputStream fos = null;
        File file = null;/*from  w ww . ja v a2  s.  c  o  m*/
        try {
            file = new File(filePath + "/" + fileName);
            fos = new FileOutputStream(file);
            bos = new BufferedOutputStream(fos);
            bos.write(bfile);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (bos != null) {
                try {
                    bos.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
        }
        return file;
    }
}

Related

  1. writeBytes(String filename, byte[] bytes)
  2. writeBytes(String filename, byte[] data, int len)
  3. writeBytes(String filePath, boolean append, byte[] content)
  4. writeBytesInFile(File f, String data)
  5. writeBytesSafely(File aFile, byte theBytes[])
  6. writeBytesToFile(byte[] byteContent, String fileName)
  7. writeBytesToFile(byte[] bytes, File file)
  8. writeBytestoFile(byte[] bytes, String filepath)
  9. writeBytesToFile(byte[] data, String path)