Computer Science, asked by anishadavid9685, 11 months ago

How to convert an object to byte array in java?

Answers

Answered by Zisha7
4

Answer:

To convert an object to byte array.

  1. Make the required object serializable interface.
  2. Create a ByteArrayOutputStream object.
  3. Create an ObjectArrayOutputStream object by passing the previous step.
  4. Write the content of the object to the output stream using the write object () method of the ObjectOutputStream class.
  5. Flush the content to the stream using the flush () method.
  6. Finally convert the contents of ByteArrayOutputStream to a byte array using the to ByteArray () method.
Similar questions