×

Discussion Board

Results 1 to 11 of 11

Thread: UTF format

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    13

    Question UTF format

    Hi,

    In my application, I have got data from a text file and loaded it in RMS. I have retrieved the data and displayed in the mobile screen using form. I have to insert some special characters like ('[single quotes]),How can i do that,Please help me.

    Thanks
    Baalu

  2. #2
    Registered User
    Join Date
    Sep 2007
    Location
    Bangalore
    Posts
    868

    Re: UTF format

    Dear balu,
    If you do readUTF() and writeUTF() It will be taken care . how r u doing ? And You have not mentioned your problem very clearly and you do that ? And how are you writing the data and reading hte dat from the RMS

  3. #3
    Super Contributor
    Join Date
    Sep 2008
    Location
    Noida, U.P.
    Posts
    1,330

    Thumbs up Re: UTF format

    Hi,
    Quote Originally Posted by baaluaanand View Post
    Hi,

    In my application, I have got data from a text file and loaded it in RMS. I have retrieved the data and displayed in the mobile screen using form. I have to insert some special characters like ('[single quotes]),How can i do that,Please help me.

    Thanks
    Baalu
    Please tell ur actual problem. What is ur actual problem? Is it related to reading writing and printing or is it related to displaying special characters? Also clarify ur process of application.
    thanks,
    jitu_goldie..

    KEEP TRYING..

  4. #4
    Registered User
    Join Date
    Mar 2009
    Posts
    13

    Re: UTF format

    sorry guyz what actually i meant was when special characters like single quotes etc are displayed, it is displayed as some box or something like this().So is it due to utf problem.Just want to clarify it.And how am i supposed to rectify these so that i can display it properly.

  5. #5
    Super Contributor
    Join Date
    Sep 2008
    Location
    Noida, U.P.
    Posts
    1,330

    Thumbs up Re: UTF format

    Quote Originally Posted by baaluaanand View Post
    sorry guyz what actually i meant was when special characters like single quotes etc are displayed, it is displayed as some box or something like this().So is it due to utf problem.Just want to clarify it.And how am i supposed to rectify these so that i can display it properly.
    use readUTF() and writeUTF() for reading and writing.
    thanks,
    jitu_goldie..

    KEEP TRYING..

  6. #6
    Registered User
    Join Date
    Mar 2009
    Posts
    13

    Re: UTF format

    So should i have to change the encoding from "ANSI" to "UTF-8"????????.Or can i use read and write UTF directly without changing the encoding

  7. #7
    Registered User
    Join Date
    Sep 2007
    Location
    Bangalore
    Posts
    868

    Re: UTF format

    Dear balu,
    You have not answered for these questions
    1. How are you writing the data in to RMS ?
    2. How are you reading the data from RMS ?
    which methods you are using ?

  8. #8
    Registered User
    Join Date
    Mar 2009
    Posts
    13

    Re: UTF format

    Hi,

    For writing the data into RMS, I am using the following code
    public void writeIntoRMS(){
    try{
    data = file("data.txt");
    for( int i = 0; i < data.length; i++) {
    byte[] rec = data[i].getBytes();
    dataRMS.addRecord(rec, 0, rec.length);
    }

    }catch (Exception e){
    e.printStackTrace();
    }
    }

    To read the RMS I am using below one :
    public String[] getData(int startIndex){
    String storeRecord[]= new String [50];
    try{
    byte[] recData = new byte[5];
    int len, count = 0;
    for(int i = startIndex; count < 5; count++,i++){
    if(dataRMS.getRecordSize(i + 1) > recData.length){
    recData = new byte[dataRMS.getRecordSize(i + 1)];
    }
    len = dataRMS.getRecord(i + 1, recData, 0);
    storeRecord[count] = new String(recData, 0, len);
    }
    }catch (Exception e){}
    return(storeRecord);
    }

    I have use the following method to get data from a text file:
    private String[] file(String path){
    InputStream is = this.getClass().getResourceAsStream(path);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    String s[] = null;
    String ss ="";
    try {
    /* DataInputStream din = new DataInputStream(is);
    int size = din.readShort();
    s = new String[size];*/
    int chars, i = 0;
    while (( i = is.read())!= -1 ) {
    baos.write(i);
    }
    ss = new String(baos.toByteArray());
    /* while ((chars = is.read()) != -1){
    ss = ss+(char)chars;
    } */
    s = split(ss,"|||");
    }catch (Exception e){e.printStackTrace();}
    return(s);
    }


    Thanks
    Baalu

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

    Re: UTF format

    Yup, you need to do like the guys say, and use writeUTF() and readUTF().

    Never use String.getBytes(), or new String(byte[], ...). These behave differently on different devices, and are usually not safe for non-ASCII characters.

    Do like you do for the shorts, and use ByteArrayOutputStream/DataOutputStream, etc, to write Strings to byte[]s.

    Cheers,
    Graham.

  10. #10
    Registered User
    Join Date
    Sep 2007
    Location
    Bangalore
    Posts
    868

    Re: UTF format

    Hi balu,
    byte[] rec = data[i].getBytes(); to byte[] rec = data[i].getBytes("UTF-8");
    When ever you read data from RMS you will receive the byte[] . If you are converting the byte to string you need to specify the encoding
    new String(byte[] , "UTF-8");

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

    Re: UTF format

    Quote Originally Posted by bhanuchandar.k View Post
    Hi balu,
    byte[] rec = data[i].getBytes(); to byte[] rec = data[i].getBytes("UTF-8");
    When ever you read data from RMS you will receive the byte[] . If you are converting the byte to string you need to specify the encoding
    new String(byte[] , "UTF-8");
    Beware that this feature is not required on MIDP-1.0 devices, and is properly specified only for JSR 185.

    Cheers,
    Graham.

Similar Threads

  1. faulty phone number format after synchronizing my Nokia 6210 with OutlookXP
    By ricvilla in forum PC Suite API and PC Connectivity SDK
    Replies: 3
    Last Post: 2006-12-28, 16:20
  2. ????????Convert Date format
    By mehulgarnara in forum Mobile Java Tools & SDKs
    Replies: 0
    Last Post: 2005-04-15, 07:34
  3. Nokia6600 vs TYPE_USHORT_565_RGB Pixel Format..
    By Niall in forum Mobile Java Tools & SDKs
    Replies: 0
    Last Post: 2003-09-16, 12:07

Posting Permissions

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