java - How to use UTF-8 character in Netbeans - Stack Overflow
java - How to use UTF-8 character in Netbeans - Stack Overflow
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
10 "". but its not supported.
String char1="世界你好";
System.out.println(char1);
Share Improve this question edited Jun 16, 2016 at 8:05 asked Feb 4, 2011 at 9:16
Follow Alexander Farber sjain
22.8k 76 255 437 1,695 9 25 37
Did you ever find a solution for this? – theyuv Mar 9, 2016 at 12:56
Related : Netbeans console does not display Bangla unicode characters – Quazi Irfan Mar 9, 2016 at
14:34
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 .
8
Works for both console input and output in NetBeans.
Share Improve this answer edited Jan 8, 2015 at 20:16 answered Jan 8, 2015 at 19:41
Follow CephBirk Mate Mate Šimović
6,680 5 58 74 Šimović's
945 11 11
1 I found that it is necessary for me to add -J-Dfile.encoding=UTF-8 in the netbeans.conf file and also
make sure that my java program is being executed with the jre parameter -Dfile.encoding=UFT-8. I
am using Maven to run my project. (Edit this under Properties/Run/VM Options.) This second step
might only be necessary if you are using Maven. – Enwired Jan 6, 2016 at 22:57
@Enwired I confirm the step you described solves some charset issues - NetBeans 12 – JRr Aug 13,
2021 at 17:43
1 de 8 18/10/2024, 20:17
java - How to use UTF-8 character in Netbeans - Stack Overflow https://stackoverflow.com/questions/4896311/how-to-use-utf-8-charact...
Jan 2023 - Update for newer versions of Java (17, 18, 19)
The approach in this answer, and its related comments recommends using the following:
4
• NetBeans config: -J-Dfile.encoding=UTF-8
This has worked perfectly well for me in the past when using the NetBeans output
window, with older versions of Java (e.g. Java 11 and 13) on older versions of NetBeans.
The caveats:
• I am using Windows (10 and 11) where the operating system default code page is
Windows-1252. If you are using a different OS, your experience may be different.
• My tests were all with Eclipse Adoptium releases of Java (17, 18 and 19).
• My NetBeans output window is using the Monospaced 12 font (see NetBeans Options
> Miscellaneous > Output). There's no point in using a font which may not support
the Unicode characters you want to print - so don't forget to check that setting.
For Java 17
Double-check that Java 17 is actually being used in Project properties > Build > Compile >
Java platform.
And, optionally, if you are using Maven, you should set these Maven options:
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
This is similar to the answer I linked to above, except that instead of using:
file.encoding=UTF-8
2 de 8 18/10/2024, 20:17
java - How to use UTF-8 character in Netbeans - Stack Overflow https://stackoverflow.com/questions/4896311/how-to-use-utf-8-charact...
sun.stdout.encoding=UTF-8
For Java 18
This is the same as Java 17, but with the Java platform (and, if relevant, Maven settings)
changed accordingly, of course.
For Java 19
Instead of using this:
sun.stdout.encoding=UTF-8
Use this:
stdout.encoding=UTF-8
I could not find any official documentation for the newer stdout.encoding , except for a reference to it in this
OpenJDK ticket. So, maybe an upcoming version of the Java Internationalization Guide will discuss it (but it's not
mentioned in the current version of that guide).
The official Java internationalization guide from v20 onwards has been updated to cover
stdout.encoding and stderr.encoding :
Note: The standard output stream System.out and the standard error output
stream System.err don't use the default charset; they use the charset specified by
Console.charset()
3 de 8 18/10/2024, 20:17
java - How to use UTF-8 character in Netbeans - Stack Overflow https://stackoverflow.com/questions/4896311/how-to-use-utf-8-charact...
Console.charset() .
Specify the encoding for System.out and System.err with the system properties
stdout.encoding and stderr.encoding , respectively. The default values of these
system properties depend on the platform. The default values take on the value of
the native.encoding property when the platform does not provide streams for the
console.
So, that's the same approach as for Java 19 - except now it's been officially documented in
the Java 20 internationalization guide (and subsequent versions of the guide).
For Java 19, you can also add the following to your Project properties > Run > VM
Options:
-Dstdout.encoding=UTF-8 -Dstderr.encoding=UTF-8
I don't know why, but you don't appear to need to add -J-Dstderr.encoding=UTF-8 to the
netbeans.conf file, as long as you do have -J-Dstdout.encoding=UTF-8 .
Where is netbeans.conf?
You can find it in a subdirectory where NetBeans is installed. On Windows, this is typically:
C:\Program Files\NetBeans-16\netbeans\etc\netbeans.conf
Make sure you add the -J-D... option inside the closing double-quotes at the end of the
(lengthy) netbeans_default_options="..." string. Also be sure to include a space to separate
this new option from the previous option in the string.
Already covered elsewhere, no doubt - but if you want to see UTF-8 output correctly in a
Windows CMD shell, then you can use the Windows chcp command:
chcp 65001
The default value (for me) is 437 - for Windows-1252 (also known as IBM437, and various
other aliases).
4 de 8 18/10/2024, 20:17
java - How to use UTF-8 character in Netbeans - Stack Overflow https://stackoverflow.com/questions/4896311/how-to-use-utf-8-charact...
Further Details
You can see more detailed discussions in various NetBeans tickets, including (but not
limited to):
netbeans 17 don't seem to have vm option – robert trudel Mar 17, 2023 at 23:22
Share Improve this answer edited Mar 11 at 16:08 answered Jan 12, 2023 at 15:59
@roberttrudel - NetBeans 17 does have Run > VM Options if you are usingandrewJames
Follow a plain Java application.
21.3k
If you are using a Web Application, then no it does not - because in that case 11 options
the VM 27 63have
to be added to whatever container you are using (Tomcat, Firefly, and so on...). Maybe that is why
you are not seeing a VM option? Otherwise, this might make a good new question you could ask.
– andrewJames Mar 17, 2023 at 23:34
sir I had added this on my netbeans properties in VM option and in my conf etc directory but the
problem not solved to enable encoding utf-8 to output numbers int [] instead of showing nums its
output show symbols [I@433c675d – Ahmed Abubaker Jul 17 at 20:30
1 @AhmedAbubaker - "problem not solved to enable encoding utf-8" - You have a different problem -
nothing to do with UTF-8. You are trying to print an array - and what you get is explained in this
answer. Try using Arrays.toString(yourArrayHere) instead - and print the resulting string.
– andrewJames Jul 17 at 21:09
1 @ andrewJames oh! sir I'm had wrong description to this problem and I mixed the concepts you are
right sir thanks this useful to me and solve it – Ahmed Abubaker Jul 17 at 23:44
5 de 8 18/10/2024, 20:17
java - How to use UTF-8 character in Netbeans - Stack Overflow https://stackoverflow.com/questions/4896311/how-to-use-utf-8-charact...
1 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.
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.
You can check this resource for help on setting character encoding
FaqI18nProjectEncoding
0
Share Improve this answer Follow answered Feb 4, 2011 at 9:23
Flexo
2,546 3 21 32
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.
0
Project Properties | Sources | Encoding
Set it to UTF8
Share Improve this answer edited Feb 4, 2011 at 9:30 answered Feb 4, 2011 at 9:21
Follow Met
3,162 4 27 43
This didn't work for me. I've been unable to get these characters to display within code in Netbeans.
✰☆★ ☞☛ ❸➂❤♡ � ✉� My project is set as UTF8. Even "Courier New"
didn't work for me, even though it does in Notepad++ with these same characters. I still haven't
been able to figure this out. – Ryan May 27, 2016 at 20:36
6 de 8 18/10/2024, 20:17
java - How to use UTF-8 character in Netbeans - Stack Overflow https://stackoverflow.com/questions/4896311/how-to-use-utf-8-charact...
7 de 8 18/10/2024, 20:17
java - How to use UTF-8 character in Netbeans - Stack Overflow https://stackoverflow.com/questions/4896311/how-to-use-utf-8-charact...
8 de 8 18/10/2024, 20:17