How to convert an object to byte array in java?
Answers
Answered by
4
Answer:
To convert an object to byte array.
- Make the required object serializable interface.
- Create a ByteArrayOutputStream object.
- Create an ObjectArrayOutputStream object by passing the previous step.
- Write the content of the object to the output stream using the write object () method of the ObjectOutputStream class.
- Flush the content to the stream using the flush () method.
- Finally convert the contents of ByteArrayOutputStream to a byte array using the to ByteArray () method.
Similar questions
English,
6 months ago
Science,
6 months ago
Biology,
6 months ago
Computer Science,
11 months ago
Computer Science,
11 months ago