怎么从propertyes文件中正确取到中文呢?
如下,是SendMail取MailServer.properties的代码MailServer.properties,文件编码为UFT-8
Subject=新留言通知在SendMail.java (文件编码为UFT-8) try
{
InputStream is = getClass().getResourceAsStream("MailServer.properties");
Properties prop = new Properties();
prop.load(is);
//乱码,怎么取到正确的文字呢
System.out.println("Subject:" + prop.get("Subject").toString());
}
如下,是SendMail取MailServer.properties的代码MailServer.properties,文件编码为UFT-8
Subject=新留言通知在SendMail.java (文件编码为UFT-8) try
{
InputStream is = getClass().getResourceAsStream("MailServer.properties");
Properties prop = new Properties();
prop.load(is);
//乱码,怎么取到正确的文字呢
System.out.println("Subject:" + prop.get("Subject").toString());
}
不能这样写中文,这样写当然是乱码,你要通过jdk/bin/native2ascii.exe转码,这样才能正常现实!
当然你下一个编辑properties文件的插件也可以!
native2ascii -encoding utf-8 MailServer_xx.properties MailServer_zh_CN.properties
jdk里带的文件编码转换工具
http://www.java2000.net/download.jsp
在最底部
那就应该可以在程序里有办法取到正确内容的,而不要改变properties文件
http://zhidao.baidu.com/question/154062493.html?push=ql