下面介紹兩個解決辦法:
1. 裝一個插件 Poperties Editor 就可以解決了!
Poperties Editor介紹:一個在編輯完成後可以將資源文件中的中文編碼格式轉換爲unicode編碼的插件,在開發國際化應用程序的時候非常有用http://propedit.sourceforge.jp/eclipse/updates/
安裝方法:在線安裝Poperties Editor
啓動eclipse,點菜單Help -> SoftWare Updates -> find and install->選中Search for new features to install ->next->點擊 New Remote site->給這個更新站點取個名字 如:luanma,url ,填寫http://propedit.sourceforge.jp/eclipse/updates即可。->點擊ok->選中剛纔新加的站點名稱,點擊finish->他會自動找出與你所用的eclipse版本相適應的插件全部選中->後面只要選擇install all即可
->最後會提示你重起你的eclipse 所有的properties文件名的前面都有一個綠色的p字.
注意:當你安裝完之後,那個properties文件裏有中文,你編譯之後它自動就會轉化了。
2. 在jdk的bin文件夾裏有個專門轉unicode的應用程序 native2ascii.exe
具體操作如下:
1) 把你要轉換的文字寫到一個文件裏,如c:/test.txt
例如:內容如下:
hello.error.name = 請輸入姓名。
hello.error.hobby = 請至少選擇一個愛好。
hello.error.age = 請輸入年齡,年齡必須大於{0}。2) 在cmd方式中轉到bin目錄,如C:/j2sdk1.4.2_04/bin
3) 輸入命令 native2ascii c:/test.txt > c:/out.txt
轉出來的內容就是這樣的:
hello.error.name = \u8bf7\u8f93\u5165\u59d3\u540d\u3002
hello.error.hobby = \u8bf7\u81f3\u5c11\u9009\u62e9\u4e00\u4e2a\u7231\u597d\u3002
hello.error.age = \u8bf7\u8f93\u5165\u5e74\u9f84\uff0c\u5e74\u9f84\u5fc5\u987b\u5927\u4e8e{0}\u3002將內容直接粘到 ApplicationResources.properties 文件的相應位置就可以了。
4) 將out.txt裏對應的編碼替代原文件的編碼即可
當然也可以這樣
native2ascii -encoding gb2312 ApplicationResources.properties ApplicationResources_zh.properties