Binary File Handling in Java
In this lesson, we will learn how to handle binary file in Java.
What is Binary File Handling
Binary File Handling is a process that allows us to create a file and store data in its original format. Unlike text files, where data is treated as plain text, binary files preserve the actual representation of data types. For instance, if we store an integer value in a binary file, it is treated as an integer, not just a sequence of characters.
Binary files are primarily used for storing records, similar to how we store data in a database. This format makes it easier to access, modify, and manage records efficiently.
We will use the following classes to handle data in a binary file:
- FileOutputStream : Used for writing streams of raw bytes to a binary file.
- DataOutputStream : Used for writing primitive data types to an output stream.
- FileInputStream : Used for reading streams of raw bytes from a binary file.
- DataInputStream : Used for reading primitive data types from an input stream.
In Java, a stream refers to the flow of data (in the form of bytes) from one source to another.
Unlock This Lesson & Start Learning!
Get full access to this lesson, practical exercises, quizzes, and your Mentora AI Tutor.
Special Offer, use coupon code DWL6BC to get additional discount of 10% on all subscription. Hurry limited time offer.
1 Month
Renews at ₹259/month.
Manual renewal required.
No automatic charges.
- Premium lessons access
- Quizzes and exercises
- Mentora AI Tutor
3 Months
Equivalent to ₹219.67/month.
Manual renewal required.
No automatic charges.
- Premium lessons access
- Quizzes and exercises
- Mentora AI Tutor
6 Months
Equivalent to ₹193.17/month.
Manual renewal required.
No automatic charges.
- Premium lessons access
- Quizzes and exercises
- Mentora AI Tutor
12 Months
Equivalent to ₹179.92/month.
Manual renewal required.
No automatic charges.
- Premium lessons access
- Quizzes and exercises
- Mentora AI Tutor