读取资源文件乱码

方法一:使用jdk自带工具native2ascii进行转码

1.首先是.properties,.jsp文件的编码格式(eclipse中来说吧,就是文件Properties的Info的Text file encoding )

2.jsp中的"charset"的设置值

首先建立建立一个ApplicationResources_cn.properties文件

内容如下:

errors.name=用户名错误

在里面写入一些信息。并以UTF-8格式保存(我使用的是eclipse,在eclipse中设置文件的Properties属性为UTF-8既可).然后在dos下,先进入ApplicationResources_cn.properties文件所在的目录。在输入以下命令:

native2ascii -encoding UTF-8  ApplicationResources_cn.properties ApplicationResources.properties

(这里要注意 -encoding 后面的参数 UTF-8,因为前面ApplicationResources_cn.properties 是以UTF-8格式保存的,所以这里一定要要用UTF-8,要不后面再怎么弄,永远也显示不出中文。我曾经就被网上一篇文章误导了,前面说用UTF-8,后面native2ascii参数既然用gb2312!

方法二:使用PropertiesEditor进行编辑

首先,按照如下方法在Eclipse中安装PropertiesEditor插件

[ INSTALLATION ]


Please choose from the screen of Eclipse with "Help" ->"Software Updates" -> "Update Manager". An 'Update Manager' opens.


In the "Feature Updates" view at the lower left of an 'Update Manager', please carry out the right click of the "Sites to Visit", and create a site bookmark by "New" -> "Site Bookmark...".
- The bookmark to create should input the following "URL" and should push an "Finish" button.
Name: Arbitrary input
URL : http://propedit.sourceforge.jp/eclipse/updates/
Bookmark type: Eclipse update site


If a site bookmark is created, the bookmark created at the bottom of "Feature Updates" will appear.
A click of "jp.gr.java_conf.ussiy.app.propedit.eclipse.feature.PropertiesEditorFeature x.x.x" displays a preview on a right window. Since the button "Install Now" is in around the lower right, please click.


Since an installation wizard starts, please click a "Next" button rapidly.


"You will need to restart the workbench for the changes to take effect. Would you like to restart now?" is displayed. Please reboot Eclipse according to a dialog.

按照上述步骤安装后,只需要设置PropertiesEditor的编码为UTF-8,则其会自动将编码保存为UTF-8,并且你在编辑的时候,他会显示为中文,而不是双字节的形式,这就是他的方便之处,建议使用

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值