Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying Arabic Text in J2me Using Eclipse

Tags:

java

java-me

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.

like image 206
Rana Anees Avatar asked Mar 16 '26 13:03

Rana Anees


2 Answers

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");
like image 134
Dev Avatar answered Mar 18 '26 03:03

Dev


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

like image 36
Mohamed Nazar Avatar answered Mar 18 '26 01:03

Mohamed Nazar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!