java 如何在 Netbeans 中使用 UTF-8 字符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4896311/
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
How to use UTF-8 character in Netbeans
提问by sjain
I am using Netbeans6.9.1 IDE and wants to show the Chinese characters in the output console using java.
I copied the Chinese charater from a web page and copied between the "". but its not supported.
我用的是Netbeans6.9.1 IDE,想用java在输出控制台中显示汉字。我从网页上复制了中文字符并在“”之间复制。但它不支持。
String char1="世界你好"; System.out.println(char1);
Do I need to do some setting in IDE or use some settings in my Java code?
我需要在 IDE 中做一些设置还是在我的 Java 代码中使用一些设置?
回答by Mate ?imovi?
Edit the file netbeans.conf
from the etc
directory located at the installation directory of NetBeans.
In the netbeans_default_options
option, add -J-Dfile.encoding=UTF-8
.
netbeans.conf
从etc
位于 NetBeans 安装目录的目录中编辑该文件。在netbeans_default_options
选项中,添加-J-Dfile.encoding=UTF-8
.
Works for both console input and output in NetBeans.
适用于 NetBeans 中的控制台输入和输出。
回答by J?rn Horstmann
Can you try this instead:
你可以试试这个吗:
String char1="\u4e16\u754c\u4f60\u597d";
System.out.println(char1);
The escape sequences get resolved by the javac compiler to the corresponding unicode codepoints, this way you are independent of the actual source code encoding. Any remaining display problems should then be caused by the console or an incomplete font.
转义序列由 javac 编译器解析为相应的 unicode 代码点,这样您就独立于实际的源代码编码。任何剩余的显示问题应该是由控制台或不完整的字体引起的。
PS: In my Netbeans installation (7.0 M2 on Ubuntu Linux) both strings mostly work except for the third character, which gets displayed as a box.
PS:在我的 Netbeans 安装(Ubuntu Linux 上的 7.0 M2)中,除了第三个字符显示为一个框外,两个字符串大部分都可以使用。
回答by DaTroop
You have to see the character encoding used by your console. Mine works fine though. Another thing to check is the character encoding used by the class file u r implementing.
您必须查看控制台使用的字符编码。不过我的工作正常。要检查的另一件事是您实现的类文件使用的字符编码。
Project Properties | Sources | Encoding
项目属性 | 来源 | 编码
Set it to UTF8
将其设置为 UTF8
回答by Flexo
You can check this resource for help on setting character encoding
您可以查看此资源以获取有关设置字符编码的帮助