This topic is now archived and is closed to further replies.


MIDP RecordStores

Recommended Posts

I''ve run in to a bit of a problem here.. I know how to write arbitrary data to a record store, but reading it in is another problem altogether. RecordStore.getRecord(n) returns byte[]; In order to actually do anything with this data I need to convert it to a String. So how do I convert byte[] in to a string? There is no String. that will do the conversion for me. Any help would be appreciated. Will

Share this post

Link to post
Share on other sites

Take a look at DataOutputStream and DataInputStream.

Writing to byte stream:

ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
byte[] data = baos.toByteArray();

Reading from stream:
ByteArrayInputStream bais = new ByteArrayInputStream(data);
DataInputStream dis = new DataInputStream(bais);
someString = dis.readUTF();
someInteger = dis.readInt();


Share this post

Link to post
Share on other sites