0

I used to be able to display UTF-8 encoding before my last windows reinstallation then I re-downloaded NetBeans and JDK (the version is specified on the title), suppose that I have these pieces of code in main method in a maven project:

public static void main(String[] args) {
        System.out.println("Đây là một văn bản Tiếng Việt");
}

I am expecting the output to display exactly like what I put in the println method.

I tried:

  • Putting the -J-Dfile.encoding=UTF-8 inside the netbeans_default_options of netbeans.conf file.

  • Downgrade the JDK version to lower version (JDK-17).

  • I also tried other font styles (Consolas, Arial, etc...) in NetBeans (both Tools -> Options -> Fonts & Colors -> Font and Tools -> Options -> Miscellaneous -> Font)

But they seem not working. Do I have to download any other font style or anything else?

Thanks for spending time to reply.

  • Maybe you are seeing the output in your CLI, wright? So maybe you are using a CLI code page which does not support outputing Vietnamese characters? – gthanop Jul 01 '23 at 05:22
  • Hello @gthanop, I am seeing it on the console of NetBeans, it used to be able to displaying Vietnamese. – Phạm Phú Khánh Jul 01 '23 at 05:26
  • In case you are certain that the files are saved in UTF-8 format then the last thing I can think of is to give the compiler [the --encoding option](https://docs.oracle.com/en/java/javase/20/docs/specs/man/javac.html#option-encoding). Maybe you should test your code without any IDE and see if it works, in order to better determine where the problem lies (eg on the IDE console, on the file encoding, on the compiler encoding, other, etc). – gthanop Jul 01 '23 at 05:36
  • I tried compile it on Terminal and PowerShell and got the unwanted ouput too. – Phạm Phú Khánh Jul 01 '23 at 06:18

1 Answers1

0

So I apparently figured it out by myself. After putting the -J-Dfile.encoding=UTF-8 inside the netbeans_default_options of netbeans.conf file, I have to change the system locale I recommend saving your progress before following these steps because it requires a system reboot:

  1. Open Run dialog by pressing Win + R Run

  2. Type intl.cpl, press enter to open Region dialog Region

  3. Switch to Administrative tab and press Change system locale Change system locale

  4. Check on Beta: Use Unicode UTF-8 for worldwide language support Beta: Use Unicode UTF-8 for worldwide language support

  5. Press OK then restart your device.

This is also the way to make Windows Command Prompt to display in UTF-8 encoding, you can learn more about it here