Archived

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

RPGeezus

MIDP RecordStores

Recommended Posts

RPGeezus    216
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
RPGeezus    216
LOL. Silly me... Never mind.

bytes[] a;
.
.
String myString = new String ( a);

Thats one way.

or

String myString = new String( RecordEnumeration.nextRecord ());

Cheers,
Will

Share this post


Link to post
Share on other sites
McMcDonald    122
Hi!

Take a look at DataOutputStream and DataInputStream.

Writing to byte stream:

ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
dos.writeUTF(someString);
dos.writeInt(someInteger);
...
dos.flush();
byte[] data = baos.toByteArray();

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


McMc

www.bytemaniac.com

Share this post


Link to post
Share on other sites