You can save byte array in this way:

  FileOutputStream fos = new FileOutputStream(strFilePath);
  String strContent = "Content";

  /*
   * 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(strContent.getBytes());

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

   fos.close();

It will create a file with your byte array

Answer from Jayyrus on Stack Overflow
🌐
Baeldung
baeldung.com › home › java › java io › writing byte[] to a file in java
Writing byte[] to a File in Java | Baeldung
December 11, 2025 - In this brief article, we learned how to write binary data from a byte[] to a file using plain Java and two popular Java utility libraries, Google Guava and Apache Commons IO.
Discussions

How to write array of bytes to a binary file in Java - Stack Overflow
How to write an array of bytes b[i] to a binary file in Java. I need to write those bytes it into a "binary file" to be able to read it later using hex editor (AXE). Some readers might be confuse... More on stackoverflow.com
🌐 stackoverflow.com
Writing array data to a binary file in Java - Stack Overflow
I'm trying to store the following arrays in binary, and read them back in after: private int[10] number; private String[10] name; private int[10] age; What is the best way to store them to a binary More on stackoverflow.com
🌐 stackoverflow.com
arrays - byte[] to file in Java - Stack Overflow
With Java: I have a byte[] that represents a file. How do I write this to a file (ie. C:\myfile.pdf) I know it's done with InputStream, but I can't seem to work it out. More on stackoverflow.com
🌐 stackoverflow.com
java - How to convert a byte to its binary string representation - Stack Overflow
For example, the bits in a byte B are 10000010, how can I assign the bits to the string str literally, that is, str = "10000010". Edit I read the byte from a binary file, and stored in th... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Mkyong
mkyong.com › home › java › java – how to save byte[] to a file
Java - How to save byte[] to a file - Mkyong.com
September 17, 2020 - package com.mkyong.io.howto; import org.apache.commons.io.FileUtils; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; public class ByteToFile { public static void main(String[] args) { try { // tested with character data and binary data // file to bytes[] byte[] bytes = Files.readAllBytes(Paths.get("/home/mkyong/test/file.txt")); // save byte[] to a file writeBytesToFile("/home/mkyong/test/file2.txt", bytes); writeBytesToFileNio("/home/mkyong/test/file3.txt", bytes); writeBytesTo
🌐
CodeJava
codejava.net › java-se › file-io › how-to-read-and-write-binary-files-in-java
How to Read and Write Binary Files in Java
January 7, 2022 - java CheckPNG Diagram.pngIf the file is really a PNG image, it prints the output: Is PNG file? trueAs you can see, using FileInputStream and FileOutputStream is really good for low level binary I/O such as analyzing a file or even create your own file format. Using BufferedInputStream and BufferedOutputStream is as same as FileInputStream and FileOutputStream. The only difference is that a buffered stream uses an array of byte internally to buffer the input and output to reduce the number of calls to the native API, hence increasing IO performance.By default, both BufferedInputStream and BufferedOutputStream has an internal buffer of 8192 bytes (8KB), but we can specify a custom buffer size at initialization.All the above examples can be re-written using buffered streams just by changing the instantiation of the streams.
🌐
GeeksforGeeks
geeksforgeeks.org › java › convert-byte-array-to-file-using-java
Convert byte[] array to File using Java - GeeksforGeeks
July 11, 2025 - ... // Java Program to convert ... file = new File(FILEPATH); // Method 1 // To write the bytes into a file static void writeByte(byte[] bytes) { // Try block to check for exceptions try { // Initialize a pointer in file ...
🌐
Javapractices
javapractices.com › topic › TopicAction.do
Java Practices->Reading and writing binary files
*/ log("Num bytes read: " + totalBytesRead); } finally { log("Closing input stream."); input.close(); } } catch (FileNotFoundException ex) { log("File not found."); } catch (IOException ex) { log(ex); } return result; } /** Write a byte array to the given file. Writing binary data is significantly simpler than reading it.
Find elsewhere
🌐
TutorialsPoint
tutorialspoint.com › article › parsing-and-formatting-a-byte-array-into-binary-in-java
Parsing and Formatting a Byte Array into Binary in Java
byte byteArr[] = new byte[] { 0x1, 0x00, 0x00 }; one = new BigInteger(byteArr); For Binary, we have used 2 as the toString() method parameter. ... import java.math.*; public class Demo { public static void main(String[] args) { // BigInteger ...
🌐
How to do in Java
howtodoinjava.com › home › i/o › writing byte[] to a file in java
Writing Byte[] to a File in Java
April 18, 2022 - The FileUtils class has method writeByteArrayToFile() that writes the byte array data into the specified file.
🌐
Attacomsian
attacomsian.com › blog › java-read-write-binary-files
How to Read and Write Binary Files in Java
December 5, 2019 - Here is an example that uses BufferedOutputStream with default buffer size to write data to a binary file: try { // create a writer FileOutputStream fos = new FileOutputStream(new File("output.dat")); BufferedOutputStream writer = new BufferedOutputStream(fos); // write data to file writer.write("Hey, there!".getBytes()); writer.write("\n".getBytes()); writer.write("How are you doing?".getBytes()); // flush remaining bytes writer.flush(); // close the writer writer.close(); } catch (IOException ex) { ex.printStackTrace(); }
🌐
Mkyong
mkyong.com › home › java › java – how to convert file to byte[]
Java - How to convert File to byte[] - Mkyong.com
September 17, 2020 - //This next line replaces all of readBytesFromFile Files.write(path, bFile,StandardOpenOption.CREATE); System.out.println(“Done”); } catch (IOException e) { e.printStackTrace(); } } 1 · Reply · mkyong · 4 years ago · Reply to dazz · We tested the code with character and binary data, and it works fine without the StandardOpenOption.CREATE`. Not sure how to simulate the above problem. 0 · Reply · Daniel Souza · 11 years ago · //Java 7 Files class: byte[] data = Files.readAllBytes(file.getPath()); 1 ·
🌐
Programiz
programiz.com › java-programming › examples › convert-file-byte-array
Java Program to Convert File to byte array and Vice-Versa
Then, we simply use the Files' write() method to write the encoded byte array to a File in the given finalPath.
🌐
Coderanch
coderanch.com › t › 391314 › java › read-write-binary-file
How do I read and write a binary file? (Beginning Java forum at Coderanch)
I wish to read and write a binary file (.gif) and I wonder how can i do it in Java application? BTW, how can i read a text file "line by line" and end by EOF? Please give me a easy example. Thanx a lot A Java Beginner.. ... Here is a simple example for reading from a text file line by line. ... Thanx a lot.. but how can i write a byte array into a file?
🌐
Dev.java
dev.java › learn › java-io › reading-writing › binary-files
Reading and Writing Binary Files - Dev.java
January 25, 2023 - You can create a file, append to a file, or write to a file by using the newOutputStream(Path, OpenOption...) method. This method opens or creates a file for writing bytes and returns an unbuffered output stream.
🌐
TutorialsPoint
tutorialspoint.com › convert-byte-array-to-file-using-java
Convert byte[] array to File using Java
June 17, 2024 - By using this algorithm, we are going to build some Java syntax to get a broad view of the problem statement. Step 1 Start the process. Step 2 Declare and import the Java packages.