Linux服务器Java输出文件中文乱码

时间:2023-03-10 00:45:13
Linux服务器Java输出文件中文乱码

使用下面语句查看编码:

String encoding = System.getProperty("file.encoding");
结果输出:ANSI_X3.4-1968,从而导致中文乱码
通过 locale 查看服务器系统编码,需要修改:
1在tomcat启动脚本里加入  -Dfile.encoding=UTF-8 选项
2修改配置文件,使得如下环境变量为这样的值:

LANG="en_US.UTF-8"
 LC_ALL="en_US.UTF-8"

可使用locale 命令测试。

最后重启服务器,即可。

参考自:https://confluence.atlassian.com/confkb/filesystem-encoding-is-written-as-ansi_x3-4-1968-even-though-the-server-is-set-to-utf-8-658735809.html