Displaying Arabic Text in J2me Using Eclipse

非 Y 不嫁゛ 提交于 2019-12-12 16:13:05

问题


I am new to J2me, kindly can anybody tell me how can I do below in J2me?

String salam="اَللّٰهُمَّ اِنِّىْ اَسْئَلُكَ رِزْقًاوَّاسِعًاطَيِّبًامِنْ رِزْقِكَ";
byte[] bytes = salam.getBytes("UTF-8");
str1=new String(bytes);
System.out.println("Arabic :"+str1);

it is displaying سلام char like that

I am using Eclipse Indigo Service Release 1.


回答1:


The below code can be use for displaying arabic text in J2ME

String s=new String("\u0628\u06A9".getBytes(), "UTF-8");

where \u0628\u06A9 is the unicode of two arabic letters




回答2:


You should use the a String contructor that allows you to specify the charset with an argument like String(byte[], Charset) (No Charset in J2ME) or String(byte[], String). Otherwise the byte array will be decoded using the platform default which may not be UTF-8.

Example:

 byte[] utf8bytes = ... //Byte array containing UTF-8 as bytes.
 String string = new String(utf8bytes, "UTF-8");



回答3:


I found the solution :
Window > Preferences > General > Content Types

Chose the type of file you want (Text=> java in your case )

Now paste UTF-8 to Default encoding and click "update".



来源:https://stackoverflow.com/questions/9161245/displaying-arabic-text-in-j2me-using-eclipse

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!