when I compile java file under mac terminal,output is garbled,how to solve it?(my OS language is chinese)
Thanks for your help.
My output is as below when it displays javac help document:
zhang-zhongdemacbook:~ zhangzhong$ javac
?÷???javac <ѡ??> <Դ?ļ?>
???У????ܵ?ѡ???????
-g ???????е?????Ϣ
-g:none ???????κε?????Ϣ
-g:{lines,vars,source} ֻ????ijЩ??????Ϣ
-nowarn ???????κξ???
-verbose ????йر?????????ִ?еIJ???????Ϣ
-deprecation ???ʹ???ѹ?ʱ?? API ??Դλ??
-classpath <·??> ָ???????û????ļ???ע?ʹ????????λ??
-cp <·??> ָ???????û????ļ???ע?ʹ????????λ??
-sourcepath <·??> ָ??????????Դ?ļ???λ??
-bootclasspath <·??> ???????????ļ???λ??
-extdirs <Ŀ¼> ???ǰ?װ????չĿ¼??λ??
-endorseddirs <Ŀ¼> ????ǩ???ı?·????λ??
-proc:{none,only} ?????Ƿ?ִ??ע?ʹ?????/????롣
-processor [,,…]Ҫ???е?ע?ʹ???????????ƣ??ƹ?Ĭ?ϵ?????????
-processorpath <·??> ָ??????ע?ʹ????????λ??
-d <Ŀ¼> ָ????????ɵ????ļ???λ??
-s <Ŀ¼> ָ????????ɵ?Դ?ļ???λ??
-implicit:{none,class} ָ???Ƿ?Ϊ??ʽ?????ļ????????ļ?
-encoding ָ??Դ?ļ?ʹ?õ??ַ?????
-source ?ṩ??ָ???汾??Դ??????
-target ?????ض? VM ?汾?????ļ?
-version ?汾??Ϣ
-help ?????ѡ?????Ҫ
-Akey[=value] ???ݸ?ע?ʹ????????ѡ??
-X ????DZ?ѡ?????Ҫ
-J ֱ?ӽ? ???ݸ?????ʱϵͳ
I assume that you mean the output of your Java program is garbled when you compile it on Mac OS. You need to make sure that either A) the character encoding of your source file is the same as that used by your workstation (most IDEs do this by default), or B) you specify the
-encodingoption ofjavacto match the file’s character encoding.If that doesn’t fix the problem, when you are running
java, make sure that the system property “file.encoding” is set to the character encoding using the command line option-Dfile.encoding=<encoding>.Note that setting this in your program with
System.setPropertywill not work. The value is read during startup of the JVM and cached. Changing it later will not affect the console output.