I am writing a Netbeans java program to handle Chinese characters in arguments. I am able to use unicode codes and Chinese characters in my coding and they compiles and display on console correctly. However, when I pass the Chinese characters via project properties run arguments, they all turn into ?????. I have already set my project encoding to UTF-8 and VM options -Dfile.encoding=UTF-8. Here is my coding, please help.
public static void main(String[] args) {
String test = "\u5973\u58eb";
System.out.println(test); //works
String test2 = "女士2";
System.out.println(test2); //works
System.out.println(args[0]); //copy&paste test2 to argument, not works, showing ??
}
NB: I use jdk 1.8.0_202, Ant v1.10.4, Windows 10, Netbeans 10, fonts used for Netbeans output and termianl are monospaced14, project is created using Netbeans "java application". Problem occurs when run within Netbeans or on Windows command prompt chcp 65001 both with -Dfile.encoding=UTF-8.
NB: With skomisa's advise, I further test with Windows "use unicode utf8 for worldwide language support" checked. I also move away from Netbeans but use the jar to run on Windows cmd with chcp 65001.
D:\.......>java -cp dist/myjar.jar -Dfile.encoding=UTF8 java.mypackage.TestUTF8 女士
女士
女士2
女士
D:\.......>java -cp dist/myjar.jar java.mypackage.TestUTF8 女士
??
??2
女士
So with -Dfile.encoding=UTF8 (first run), constant string in coding works while arguments not. Without -Dfile.encoding (second run), in-code constants not work while arguments works. But I need both. I have Chinese constant string in my program as well as in program arguments. Can somebody tell me what can be done please.