Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print arabic string in java

Tags:

java

eclipse

I'm trying to display arabic text in java but it shows junk characters(Example : ¤[ï߯[î) or sometimes only question marks when i print. How do i make it to print arabic. I heard that its something related to unicode and UTF-8. This is the first time i'm working with languages so no idea. I'm using Eclipse Indigo IDE.

EDIT: If i use UTF-8 encoding then "¤[ï߯[î" characters are becoming "????????" characters.

like image 383
Chandra Eskay Avatar asked May 21 '12 09:05

Chandra Eskay


3 Answers

For starters you could take a look here. This should allow you to make Eclipse print unicode in its console (which I do not know if it is something which Eclipse supports out of the box without any extra tweaks)

If that does not solve your problem you most likely have an issue with the encoding your program is using, so you might want to create strings in some manner similar to this:

String str = new String("تعطي يونيكود رقما فريدا لكل حرف".getBytes(), "UTF-8");

This at least works for me.

like image 178
npinti Avatar answered Nov 18 '22 11:11

npinti


This is for Java SE, Java EE, or Java ME? If this is for Java ME, you have to make custom GlyphUtils if you use LWUIT. Download this file: http://dl.dropbox.com/u/55295133/U0600.pdf Look list of unicode encoding.. And look at this thread: https://stackoverflow.com/a/9172732/1061371 in the answer (post) of Mohamed Nazar that edited by bernama Alex Kliuchnikau, "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" Look at U0600.pdf file, so we can see that Mohamed Nazar and Alex Kliuchnikau give example to create "ba" and "kaf" character in arabic.

Then the last point that you must consider is: "Make sure your UI support unicode(I mean arabic) character." Like LWUIT not support yet unicode (I mean arabic) character. You should make your custom code if you mean your app is using LWUIT.

like image 1
chameleon Avatar answered Nov 18 '22 12:11

chameleon


If you embed the text literally in the code make sure you set the encoding for your project correctly.

like image 2
Joey Avatar answered Nov 18 '22 11:11

Joey