How to use the UTF-8 character in Netbeans

I am using Netbeans6.9.1 IDE and want to show Chinese characters in output console using java. I copied the Chinese charter from a web page and copied between. "But not supported.

  String char1 = "世界 你好";
          System.out.println (char1);

Do I need to make some settings in the IDE or use some settings in my Java code?

+4
source share
4 answers

Modify the netbeans.conf file in the etc directory located in the NetBeans installation directory. In the netbeans_default_options option, add -J-Dfile.encoding=UTF-8 .

Works for input and output of the console in NetBeans.

+2
source

Can you try this:

 String char1="\u4e16\u754c\u4f60\u597d"; System.out.println(char1); 

Equivalent sequences are resolved by the javac compiler to the corresponding Unicode code points, so you are not dependent on the actual encoding of the source code. Any remaining display problems should be caused by the console or an incomplete font.

PS: In my Netbeans installation (7.0 M2 on Ubuntu Linux), both lines basically work, with the exception of the third character, which appears as a field.

+1
source

You should see the character encoding used by your console. Mine works great. Another thing to check is the character encoding used in the u r class file.

Project Properties | Sources | Coding

Set it to UTF8

0
source

You can check this resource for help setting up character encoding.

FaqI18nProjectEncoding

0
source

Source: https://habr.com/ru/post/1338394/