×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Jun 2012
    Posts
    7

    How write unicode in file S40

    Hi i use this example to create file and save String http://www.developer.nokia.com/Commu...ile_in_Java_ME .
    Everything is ok but in places where are unicode characters i have in Notepad "??". How to write unicode characters to display correctly in Notepad? Any ideas? I use Polish characters. Thx for reply.
    I use Nokia 2710 Navi.

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

    Re: How write unicode in file S40

    OK... two things you need to do...

    This line of the example is a problem:

    Code:
    byte data[] = string.getBytes();
    You should change it to:
    Code:
    byte data[] = string.getBytes("UTF-8");
    (I've changed it in the example in the wiki.)

    I recommend never using getBytes() without specifying the encoding (and, if you specify an encoding, always specify UTF-8, since it's the only one the spec requires devices to support). Otherwise the device choses the encoding to use. It will probably choose ISO 8859 Latin 1... fine for us in Western Europe, useless in Poland... or the entire rest of the world. (More importantly, you don't know what it will choose, so you might get different results on different devices.)

    Second, you might want to prefix the string (before you convert it to bytes) with a '\ufeff' byte order mark character. This will tell notepad that the file it's loading is UTF-8 and not some other encoding.

    Code:
    byte[] data = ("\ufeff" + string).getBytes("UTF-8");
    You should get something that notepad will like.

    Graham.

  3. #3
    Registered User
    Join Date
    Jun 2012
    Posts
    7

    Re: How write unicode in file S40

    Yeaa! It work thank you very much for help. You have beer from me

Similar Threads

  1. Replies: 1
    Last Post: 2012-02-28, 23:00
  2. very simple middlet class to write to write a text file
    By a_sina_a in forum Mobile Java General
    Replies: 10
    Last Post: 2008-03-07, 16:35
  3. Replies: 3
    Last Post: 2005-08-01, 13:39
  4. write any unicode chars in ABC mode
    By mhamed24 in forum Symbian
    Replies: 1
    Last Post: 2004-05-02, 03:31
  5. Reading from Unicode file
    By xdimas in forum Mobile Java General
    Replies: 3
    Last Post: 2004-03-22, 13:40

Posting Permissions

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