SpringSecurity3 读取中文消息资源(properties)文件,输出乱码的问题

因为Java识别编码为Unicode,而计算机系统编码常常是GBK,UTF8等编码,所以要转换为Unicode编码
这时可以用Java\jdk1.x.x\bin\native2ascii.exe工具。 用JDK提供的native2ascii,进行编码转换
用法:native2ascii [-reverse] [-encoding 源文件的编码] [文件 [输出文件]]

例如,把messages_zh_CN1.properties转换成messages_zh_CN2.properties。 

先把要转换的文件messages_zh_CN1.properties放到Java\jdk1.x.x\bin\目录下,然后cmd进入bin的当前目录下输入 

native2ascii -encoding UTF-8 messages_zh_CN1.properties messages_zh_CN2.properties

回车OKay!

#ascii =>Unicode
native2ascii messages_input.properties messages_zh_CN.properties
#UTF-8=>Unicode
native2ascii -encoding UTF-8 messages_input.properties messages_zh_CN.properties
#GBK=>Unicode
native2ascii -encoding GBK messages_input.properties messages_zh_CN.properties

注意源文件保存时的编码格式,否则转换后,输出时一样有乱码!

原文地址:https://www.cnblogs.com/jasontec/p/9601751.html