J2ME: perferred way to save / load data?

K

Kevin

Hi,

I am pretty new to J2ME, can anyone give some hits of the good ways to
save / load data on these mobile devices using J2ME? Thanks a lot.

The way I currently know is:
to use the javax.microedition.rms.RecordStore
But it only handles byte[] arrays.
How about int, double, and Date (object)?
I know I can convert int and double to byte[], but not Date. (also,
this sounds not good).

Or, we can just use a file with java.io.DataInputStream like those in
normal j2se?

Any performance issues there?

Thanks a lot.
 
T

Thomas Hawtin

Kevin said:
I am pretty new to J2ME, can anyone give some hits of the good ways to
save / load data on these mobile devices using J2ME? Thanks a lot.

The way I currently know is:
to use the javax.microedition.rms.RecordStore
But it only handles byte[] arrays.
How about int, double, and Date (object)?
I know I can convert int and double to byte[], but not Date. (also,
this sounds not good).

Or, we can just use a file with java.io.DataInputStream like those in
normal j2se?

The obvious way to do it is with Data(In|Out)putStream feeding to a
ByteArray(In|Out)putStream.

Date can be converted into a long with getTime.

Tom Hawtin
 
K

Kevin

So we must convert all these int (4 bytes), double (8 bytes), long (8
bytes) to byte[] arrays? Sounds not like a decent idea.......

How about to use the java.io.DataInputStream? I heard it may not have
good performance.

By the way, for RecordStore, is the get record by ID a "random access"
to the underlying file? Will the system hold all the records in memory?


Thanks all. :)

Thomas said:
Kevin said:
I am pretty new to J2ME, can anyone give some hits of the good ways to
save / load data on these mobile devices using J2ME? Thanks a lot.

The way I currently know is:
to use the javax.microedition.rms.RecordStore
But it only handles byte[] arrays.
How about int, double, and Date (object)?
I know I can convert int and double to byte[], but not Date. (also,
this sounds not good).

Or, we can just use a file with java.io.DataInputStream like those in
normal j2se?

The obvious way to do it is with Data(In|Out)putStream feeding to a
ByteArray(In|Out)putStream.

Date can be converted into a long with getTime.

Tom Hawtin
 
A

AlecB

Thomas said:
Kevin said:
I am pretty new to J2ME, can anyone give some hits of the good ways to
save / load data on these mobile devices using J2ME? Thanks a lot.

The way I currently know is:
to use the javax.microedition.rms.RecordStore
But it only handles byte[] arrays.
How about int, double, and Date (object)?
I know I can convert int and double to byte[], but not Date. (also,
this sounds not good).

Or, we can just use a file with java.io.DataInputStream like those in
normal j2se?
The obvious way to do it is with Data(In|Out)putStream feeding to a
ByteArray(In|Out)putStream.

Date can be converted into a long with getTime.

Tom Hawtin

So we must convert all these int (4 bytes), double (8 bytes), long (8
bytes) to byte[] arrays? Sounds not like a decent idea.......

How about to use the java.io.DataInputStream? I heard it may not have
good performance.

By the way, for RecordStore, is the get record by ID a "random access"
to the underlying file? Will the system hold all the records in memory?


Thanks all. :)

IFYP.

The recordstore can be accessed randomly. Be careful though, if you
perform deletes, the id of the first record will not be 1, which means
using a recordstore enumeration.

Data(In|Out)putStreams are very slow on certain devices. I recommend
only using them when you absolutely have to. you can usually do the
conversion yourself.

Regards,
Alec
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top