aspose file tools*
The moose likes Java Micro Edition and the fly likes Reading unicode characters from a file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "Reading unicode characters from a file" Watch "Reading unicode characters from a file" New topic
Author

Reading unicode characters from a file

Ahsan Saeed
Ranch Hand

Joined: Sep 12, 2003
Posts: 34
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

Joined: Nov 14, 2000
Posts: 1953
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

Joined: Nov 14, 2000
Posts: 1953
Remember, char is just 2 byte unsigned int.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reading unicode characters from a file