How to get a byte[] from an object
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Craig_Reichenbach
Posted On:   Thursday, November 15, 2001 11:28 AM

Hi,

Can someone please point me in the right direction? I'd like to get an array of bytes from an object, but not for serialization to a file or db. In other words I don't want to use an ObjectOutputStream to write to a file. I want to get my hands on the objects byte[] for other purposes. Is this possible?



Thanks,

Craig

Re: How to get a byte[] from an object

Posted By:   Sergey_Opanasets  
Posted On:   Thursday, November 15, 2001 11:44 AM


Object object = new Object();


try {


ByteArrayOutputStream bout = new ByteArrayOutputStream();


ObjectOutputStream oout = new ObjectOutputStream(bout);


oout.writeObject(object);


byte [] array = bout.toByteArray();


} catch (IOException ioe) {}


About | Sitemap | Contact