Java FileOutputStream Write Byte Array writeBytestoFile(byte[] bytes, String filepath)

Here you can find the source of writeBytestoFile(byte[] bytes, String filepath)

Description

write Bytesto File

License

Apache License

Declaration

public static boolean writeBytestoFile(byte[] bytes, String filepath) throws Exception 

Method Source Code


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

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

public class Main {
    public static boolean writeBytestoFile(byte[] bytes, String filepath) throws Exception {
        boolean ok = true;
        FileOutputStream fos = null;
        try {//from  w ww.  j  av  a 2 s . co m
            File f = new File(filepath);
            if (!f.getParentFile().exists()) {
                f.getParentFile().mkdirs();
            }
            fos = new FileOutputStream(f);
            fos.write(bytes);
            fos.close();
        } catch (IOException e) {
            ok = false;
        } finally {
            if (fos != null)
                fos.close();
        }
        return ok;
    }
}

Related

  1. writeBytesInFile(File f, String data)
  2. writeBytesSafely(File aFile, byte theBytes[])
  3. writeBytesToFile(byte[] bfile, String filePath, String fileName)
  4. writeBytesToFile(byte[] byteContent, String fileName)
  5. writeBytesToFile(byte[] bytes, File file)
  6. writeBytesToFile(byte[] data, String path)
  7. writeBytesToFile(File destination, byte[] bytes)
  8. writeBytesToFile(File file, byte[] bytes)
  9. writeBytesToFile(File theFile, byte[] bytes)