eclipse 在java中打印阿拉伯字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10682292/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Print arabic string in java
提问by Chandra Eskay
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.
我正在尝试在 Java 中显示阿拉伯语文本,但它显示垃圾字符(例如:¤[??ˉ[?) 或有时在我打印时只显示问号。我如何使它打印阿拉伯语。我听说它与 unicode 和 UTF-8 有关。这是我第一次使用语言,所以不知道。我正在使用 Eclipse Indigo IDE。
EDIT: If i use UTF-8 encoding then "¤[??ˉ[?" characters are becoming "????????" characters.
编辑:如果我使用 UTF-8 编码,那么“¤[??ˉ[?” 字符正在变成“????????” 人物。
采纳答案by npinti
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)
首先你可以看看这里。这应该允许您在其控制台中使 Eclipse 打印 unicode(我不知道它是否是 Eclipse 开箱即用支持的东西,无需任何额外的调整)
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");
String str = new String("???? ??????? ???? ????? ??? ???".getBytes(), "UTF-8");
This at least works for me.
这至少对我有用。
回答by Joey
If you embed the text literally in the code make sure you set the encoding for your project correctly.
如果您在代码中逐字嵌入文本,请确保正确设置项目的编码。
回答by chameleon
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.pdfLook list of unicode encoding..
And look at this thread:
https://stackoverflow.com/a/9172732/1061371in 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\u06A9is 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.
这是用于 Java SE、Java EE 还是 Java ME?如果这是针对 Java ME,则在使用 LWUIT 时必须自定义 GlyphUtils。下载此文件:http:
//dl.dropbox.com/u/55295133/U0600.pdfunicode 编码的查找列表.. 看看这个线程:https:
//stackoverflow.com/a/9172732/1061371在答案中(post) 由 bernama Alex Kliuchnikau 编辑的 Mohamed Nazar,“下面的代码可用于在 J2MEString s=new String("\u0628\u06A9".getBytes(), "UTF-8");中显示阿拉伯文本,其中\u0628\u06A9是两个阿拉伯字母的 unicode” 查看 U0600.pdf 文件,因此我们可以看到 Mohamed Nazar 和Alex Kliuchnikau 举例说明了用阿拉伯语创建“ba”和“kaf”字符。
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.
那么您必须考虑的最后一点是:“确保您的 UI 支持 unicode(我的意思是阿拉伯语)字符。” 像 LWUIT 还不支持 unicode(我的意思是阿拉伯语)字符。如果您的应用程序使用 LWUIT,则应该制作自定义代码。

