• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Object to byte[] conversion

 
Deepan Devadasan
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

will straightway come to the problem..

in J2ME how can we convert an Object to byte[], basically to write to the RecordStore...?

Since my Contact object has my attributes, i dont want to go with the sticky String.getBytes() approach....
 
Eduardo Marques
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

The usual technique is to use ByteArrayOutputStream/DataOutputStream for converting data to a byte array and ByteArrayInputStream/DataInputStream for the inverse.

See an example here.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depends what subset of Java ME you're using. If you're using CLDC, then Eduardo's answer is good. If you're using CDC, you can also use standard Java serialization with ObjectInputStream and ObjectOutputStream.
 
Deepan Devadasan
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends..

That was helpful..

Thanks for variation in CDC as well..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic