Linux环境下"Font font = new Font("黑体", Font.BOLD, 18)"中文乱码
Linux环境下"Font font = new Font("黑体", Font.BOLD, 18)"[BufferedImage~Graphics~drawString]中文乱码,windows下不会乱码,但在linux下nginx和tomcat部署后出现乱码、方框、问号等等,不能认清楚!
先说说系统:
Microsoft Windows [版本 10.0.10586]
(c) 2015 Microsoft Corporation。保留所有权利。
CentOS release 6.5 (Final)
Kernel \r on an \m
tomcat 8.0.28
好了,说怎么解决的吧步骤:
1:查看CentOS下”/usr/share/fonts“目录,查看新的系统则为空目录;
2:打开”C:\Windows\WinSxS\amd64_microsoft-windows-font-truetype-simsunb_31bf3856ad364e35_10.0.10586.0_none_1d80224ec6470747“等目录下,找到自己需要的字体的目录,那个文件夹也是见名知意了;
3:之后把挑选的字体,可以建个文件夹,一次传到Xftp等上传到服务器的”/usr/share/fonts“的目录下;
4:进入"cd /usr/share/fonts/windowsFonts"文件夹,注:windowsFonts为我挑选字体目录:
有楷体,黑体,简宋体,微软雅黑等!windowsFonts字体下载地址:http://download.csdn.net/detail/typa01_kk/9423924
5:最后在此目录下,执行"#fc-cache -fv",扫描字体目录并生成字体信息的缓存,然后应用程序就可以"立即"使用这些新安装的字体;
6:最终还是要重启tomcat了,字体生效!
执行命令 fc-cache -fv:
[root@timespacexstar windowsFonts]# fc-cache -fv
/usr/share/fonts: caching, new cache contents: 0 fonts, 1 dirs
/usr/share/fonts/windowsFonts: caching, new cache contents: 8 fonts, 0 dirs
/usr/share/X11/fonts/Type1: skipping, no such directory
/usr/share/X11/fonts/TTF: skipping, no such directory
/usr/local/share/fonts: skipping, no such directory
/root/.fonts: skipping, no such directory
/var/cache/fontconfig: cleaning cache directory
/root/.fontconfig: not cleaning non-existent cache directory
fc-cache: succeeded
包涵字体:
[root@timespacexstar windowsFonts]# ll
total 77796
-rw-r--r-- 1 root root 16299048 Jan 31 17:43 msyhbd.ttc
-rw-r--r-- 1 root root 23608184 Jan 31 17:43 msyh.ttc
-rw-r--r-- 1 root root 9751720 Jan 31 17:45 simhei.ttf
-rw-r--r-- 1 root root 11785184 Jan 31 17:46 simkai.ttf
-rw-r--r-- 1 root root 18209004 Jan 31 17:47 simsun.ttc