Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading unicode characters from a file

 
Ahsan Saeed
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remember, char is just 2 byte unsigned int.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic