Java Utililty Methods FileOutputStream Write Byte Array

List of utility methods to do FileOutputStream Write Byte Array

Description

The list of methods to do FileOutputStream Write Byte Array are organized into topic(s).

Method

FileOutputStreamwriteBytes(int[] data, String filename)
Writes data from the integer array to disk as raw bytes, overwriting the old file if present.
FileOutputStream out = new FileOutputStream(filename, false);
writeBytes(data, out);
return out;
voidwriteBytes(int[] data, String filename)
Writes data from the integer array to disk as raw bytes.
FileOutputStream out = new FileOutputStream(filename);
byte[] b = new byte[4];
for (int word : data) {
    for (int i = 0; i < 4; i++) {
        int offset = (b.length - 1 - i) * 8;
        b[i] = (byte) ((word >>> offset) & 0xFF);
    out.write(b);
...
voidwriteBytes(String filename, byte[] bytes)
write Bytes
FileOutputStream output = new FileOutputStream(filename);
output.write(bytes);
output.close();
voidwriteBytes(String filename, byte[] data, int len)
write Bytes
if (filename == null || filename.isEmpty()) {
    return;
try (FileOutputStream out = new FileOutputStream(filename)) {
    out.write(data, 0, len);
voidwriteBytes(String filePath, boolean append, byte[] content)
write Bytes
FileOutputStream fos = new FileOutputStream(filePath, append);
try {
    fos.write(content);
    fos.flush();
} finally {
    fos.close();
voidwriteBytesInFile(File f, String data)
write Bytes In File
writeBytesInFile(f, data.getBytes());
voidwriteBytesSafely(File aFile, byte theBytes[])
Writes the given bytes (within the specified range) to the given file, with an option for doing it "safely".
if (theBytes == null) {
    aFile.delete();
    return;
if (!aFile.exists()) {
    writeBytes(aFile, theBytes);
    return;
File bfile = new File(aFile.getPath() + ".rmbak");
copyFile(aFile, bfile);
writeBytes(aFile, theBytes);
bfile.delete();
FilewriteBytesToFile(byte[] bfile, String filePath, String fileName)
write Bytes To File
BufferedOutputStream bos = null;
FileOutputStream fos = null;
File file = null;
try {
    file = new File(filePath + "/" + fileName);
    fos = new FileOutputStream(file);
    bos = new BufferedOutputStream(fos);
    bos.write(bfile);
...
voidwriteBytesToFile(byte[] byteContent, String fileName)
* Output Bytes to file ******************************************.
File kekFile = new File("c:\\temp\\" + fileName);
FileOutputStream f = new FileOutputStream(kekFile);
f.write(byteContent);
f.close();
voidwriteBytesToFile(byte[] bytes, File file)
write Bytes To File
try {
    FileOutputStream out = new FileOutputStream(file);
    out.write(bytes);
    out.close();
} catch (IOException e) {
    e.printStackTrace();