mac终端输出下的javac命令出现乱码 [英] javac command under mac terminal output garbled

查看:65
本文介绍了mac终端输出下的javac命令出现乱码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在mac终端下编译java文件时,输出乱码,如何解决?(我的OS语言是中文)

when I compile java file under mac terminal,output is garbled,how to solve it?(my OS language is chinese)

感谢您的帮助.当显示javac帮助文档时,我的输出如下所示:zhang-zhongdemacbook:〜zhangzhong $ javac?÷??? javac<ѡ??><Դ?ļ?>???У????ܵ?ѡ???????-g ???????е??????Ϣ-g:无???????κε?????Ϣ-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}ָ???Ƿ?Ϊ??ʽ??????ļ?????????ļ?-编码ָ??Դ?ļ?ʹ?õ?õ??ַ??????-source?ṩ??ָ???汾??Դ?????????-target ?????ض?VM?汾??????ļ?版本?汾??Ϣ-help ??????׼ѡ??????Ҫ-Akey [= value] ???ݸ?ע?ʹ???????????ѡ??-X ????DZ?׼ѡ??????Ҫ-Jֱ?ӽ????ݸ??????ʱϵͳ

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 ֱ?ӽ? ???ݸ?????ʱϵͳ

推荐答案

我假设您的意思是在Mac OS上编译Java程序时,它的输出是乱码.您需要确保A)源文件的字符编码与工作站使用的字符编码相同(大多数IDE默认情况下都这样做),或B)您指定 -encoding 选项 javac 的名称以匹配文件的字符编码.

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 -encoding option of javac to match the file's character encoding.

如果这不能解决问题,则在运行 java 时,请确保使用命令行选项将系统属性"file.encoding"设置为字符编码.-Dfile.encoding =< 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>.

请注意,使用 System.setProperty 在程序中设置此设置将无效.在JVM启动期间读取该值并进行缓存.以后更改它不会影响控制台输出.

Note that setting this in your program with System.setProperty will not work. The value is read during startup of the JVM and cached. Changing it later will not affect the console output.

这篇关于mac终端输出下的javac命令出现乱码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆