Skip to main content
GameDev.net gamedev.net
🔒 Locked

MIDP RecordStores

Started by RPGeezus Jan 22, 2004 at 9:33 PM 1 replies 400+ views
Original Post
RPGeezus
RPGeezus
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
RPGeezus
RPGeezus
LOL. Silly me... Never mind.

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

Thats one way.

or

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

Cheers,
Will

McMcDonald
McMcDonald
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.