×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Aug 2010
    Posts
    2

    Store string more than 32 characters

    Here is my code to store string in the rms.
    Code:
    public void saveRecord(String record) {
            try {
                db = RecordStore.openRecordStore("database", true);
            }
            catch (RecordStoreException ex) {
            }
            
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
    	DataOutputStream outputStream = new DataOutputStream(baos);
            
    	try {
    	    outputStream.writeUTF(record);
    	}
    	catch (IOException ioe) {
    	    System.out.println(ioe);
    	}
    
    	byte[] b = baos.toByteArray();
    
    	try {
    	    db.addRecord(b, 0, b.length);
    	}
    	catch (RecordStoreException rse) {
    	}
        }
    
    public void loadRecord() {
            try {
                db = RecordStore.openRecordStore("database",true);
                re = db.enumerateRecords(null, null, true);
                while(re.hasNextElement()) {
                    String record = new String(re.nextRecord()).trim();
                    list.append(record, null);
                }
            }
            catch(Exception ex) {}
        }
    When I try to store a string that exceeds 32 characters and tries to load it, the string will have an extra character in front.

    Example.

    stringtostore = "123456789012345678901234567890123"

    when I load the data from the rms, it returns "$123456789012345678901234567890123" instead. Not only a dollar sign but other symbols with different length of string to store. How do I fix this?

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Store string more than 32 characters

    Welcome to Forum Nokia!!

    Two problems with this code.

    First, if you create the byte[] using DataOutput.writeUTF(), then you must read it back using DataInput.readUTF().

    Second, you don't appear to close the record stores anywhere. Record stores must be closed after use, or the application risks losing or corrupting data.

    You might find this article, in the wiki, useful.

    Graham.

  3. #3
    Registered User
    Join Date
    Aug 2010
    Posts
    2

    Re: Store string more than 32 characters

    Thank you so much! readUTF works!

    FYI, the "close record store" function exist outside of the functions, so I did close the record stores.

    Any how, thanks a lot!

Similar Threads

  1. dial a string (with pause characters) in FP2
    By noam.segal in forum Symbian
    Replies: 3
    Last Post: 2011-03-14, 16:21
  2. Store string in Record Store
    By Nourayn in forum Mobile Java General
    Replies: 15
    Last Post: 2010-08-21, 04:08
  3. How to define a long string resource (> 1024 characters)?
    By flokrates in forum Symbian Tools & SDKs
    Replies: 4
    Last Post: 2009-09-08, 10:45
  4. Replies: 2
    Last Post: 2009-05-18, 06:32
  5. how many characters can i store by name
    By jeanfy in forum Multimodecards
    Replies: 1
    Last Post: 2002-08-10, 07:48

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×