![]() |
VOOZH | about |
The Binary files contain data in a format that is not human-readable. To make them suitable for storing complex data structures efficiently, in Java, we can read from and write to binary files using the Input and Output Streams.
In this article, we will learn and see the code implementation to read and write binary files in Java.
InputStream inputStream = new FileInputStream("data.bin");
int data;
while ((data = inputStream.read()) != -1) {
// Process the read data
}
inputStream.close();
OutputStream outputStream = new FileOutputStream("data.bin");
// Write data to the output stream
outputStream.close();
Below is the implementation of Read and Write Binary Files in Java:
Hello
Writing to a Binary File:
Reading from a Binary File: