每当我打开Eclipse 或者是MyEclipse的**.PRoperties中后。或是自己新建的一个*.properties。然后再进行写入中文后,你就会发现你所输入的中文都变成了Unicode码。如下:
那么我们需要把Unicode转换成UTF-8的格式。让我们输入的中文可以展示出来。能让我们理解且看得懂的中文。 方法有两种:
打开myeclipse的: Window ->Perferences ->General ->Editors ->Context Types 或者: Window ->Perferences ->General ->Context Types 展开右边的Text节点,选中java Properties File。把下面的Default Character Set的值:ISO-8859-1改成UTF-8 如图下:当 然。如果以后你要用到Unicode编码时。你就可以执行上面的步骤,再转回来。
Java代码中进行格式转换 Configuration cfg = new Configuration("etc/orgInfo.properties"); String _orgName = cfg.getValue("ORGNAME"); System.out.println("改格式前" + _orgName); //需要进行编码格式转换,不然会乱码 String cn_orgName = new String(_orgName.getBytes("ISO-8859-1"),"utf-8"); orgName.setAttribute("value", cn_orgName);新闻热点
疑难解答