Commit b4be296
committed
feat: add DataInputStreamsExample to demonstrate deserialization with DataInputStream
WHAT:
- Implemented `DataInputStreamsExample` to read binary data (int, UTF strings, float) using `DataInputStream`.
- Created a `Student1` object and populated its fields (`rollno`, `name`, `dept`, `avg`) by reading in order.
- Printed the student details after successful deserialization.
WHY:
- `DataInputStream` allows reading primitive data types and strings in a machine-independent way.
- Ensures that the data written using `DataOutputStream` can be reconstructed exactly in the same order.
- Highlights the importance of **maintaining the same read/write order** for correct deserialization.
HOW:
1. Opened a file with `FileInputStream`.
2. Wrapped it with `DataInputStream` to read structured binary data.
3. Read data sequentially (must match the order of `DataOutputStream.write...()`).
4. Closed resources after use.
REAL-WORLD USE CASES:
- Used in serialization workflows for saving and retrieving student records, employee data, or configuration values.
- Useful for reading binary files where fields are encoded as primitive types.
- Forms the foundation for building custom serialization frameworks and structured data exchange.
NOTES:
- Always ensure `write` and `read` sequence match to avoid `EOFException` or corrupted data.
- Best practice: use **try-with-resources** instead of manual close for cleaner resource management.
- Minor issue: `dis.close()` is called twice, which is redundant (should only be once).
Signed-off-by: https://github.com/Someshdiwan <[email protected]>1 parent 11e1bc7 commit b4be296
File tree
1 file changed
+0
-25
lines changed- Section23JavaIOStreams/Serialisation Storing Data in a File/src
1 file changed
+0
-25
lines changedLines changed: 0 additions & 25 deletions
This file was deleted.
0 commit comments