Convert object to byte[] in Java
This article shows how to convert an object to byte[] or byte array and vice versa in Java. 1. Convert an object to byte[] The below example show how to use ByteArrayOutputStream and ObjectOutputStream to convert an object to byte[]. // Convert object to byte[] public static byte[] convertObjectToBytes(Object obj) { ByteArrayOutputStream boas = new …