I need to send my phone contacts in android as bytes. So i have crated a bean class implementing serializable , but after converting the arraylist of bean class to byte array, byte array is always showing null. Here is my sample code.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(presentContacts);
byte[] buf = baos.toByteArray();
Here presentContacts is the ArrayList of bean class. Byte array, buf is always returning null but presentContacts is not null.
You should probably close or at least flush the ObjectOutputStream.
Something like this
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(presentContacts);
oos.flush();
byte[] buf = baos.toByteArray();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With