Jump to content
  • Advertisement

Archived

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

RPGeezus

MIDP RecordStores

This topic is 5414 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!