Win a copy of High Performance Python for Data Analytics this week in the Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Reading unicode characters from a file

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I have some unicode characters in a text file. While saving it I selected 'Unicode' as the encoding scheme.

In my midlet I am using the following code snippet:

reader=new InputStreamReader(inputstream,"UTF16");

But when I run this, I see unicode characters. Text should be displayed in Arabic, but why is it not being displayed in Arabic ?

I have also tried saving the text file in UTF-8 encoding and then reading it by passing the "UTF-8 " encoding in the constructor, but I am still facing this problem.

If I hardcode the unicode characters in a StringItem, then the text is displayed in Arabic.

Can anyone help me with this one...

Ahsan
 
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that I met this problem before in a different situation.

If my guess is correct, then this is a typical problem, since when you read unicode in, the unicode is treated ASIS, that means String literal "\u554A", instead of Chinese 啊

How to do it, write a conversion static method, and change it to char array.
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Remember, char is just 2 byte unsigned int.
 
The knights of nee want a shrubbery. And a tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic