J2ME: perferred way to save / load data?

Discussion in 'Java' started by Kevin, Jul 6, 2006.

  1. Kevin

    Kevin Guest

    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.
     
    Kevin, Jul 6, 2006
    #1
    1. Advertising

  2. Kevin wrote:
    >
    > 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
    --
    Unemployed English Java programmer
    http://jroller.com/page/tackline/
     
    Thomas Hawtin, Jul 6, 2006
    #2
    1. Advertising

  3. Kevin

    Kevin Guest

    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 Hawtin wrote:
    > Kevin wrote:
    > >
    > > 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
    > --
    > Unemployed English Java programmer
    > http://jroller.com/page/tackline/
     
    Kevin, Jul 6, 2006
    #3
  4. Kevin

    AlecB Guest

    > Thomas Hawtin wrote:
    >> Kevin wrote:
    >>> 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
    >> --
    >> Unemployed English Java programmer
    >> http://jroller.com/page/tackline/

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

    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
     
    AlecB, Jul 7, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    9,048
    Heinz Ozwirk
    Aug 9, 2006
  2. mca
    Replies:
    0
    Views:
    110
  3. howa
    Replies:
    2
    Views:
    107
    Richard Cornford
    Apr 15, 2007
  4. howa

    Perferred way to create object

    howa, Jul 4, 2007, in forum: Javascript
    Replies:
    2
    Views:
    91
  5. howa
    Replies:
    2
    Views:
    100
    scripts.contact
    Jul 26, 2007
Loading...

Share This Page