问题
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 (No String(byte[], Charset)
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