ResourceBundle (讀取properties文件及中文亂碼解決方法)


原文:http://blog.csdn.net/joecheungdishuiya/article/details/6304993

 

 

 

public class test {
 static ResourceBundle rsb;
 /**
  * @param args
  * @throws UnsupportedEncodingException 
  */
 public static void main(String[] args) throws UnsupportedEncodingException {
  // TODO Auto-generated method stub
      rsb=ResourceBundle.getBundle("address_all");
      String keyValue = new String(rsb.getString("chainsaveservlet.save").getBytes("ISO-8859-1"), "GBK");  
      System.out.println(keyValue);
 }

}

 

 

中文亂碼解決

1.解決方法一:在使用keyValue時,進行編碼轉換

String keyValue = new String(rb.getString(keyName).getBytes("ISO-8859-1"), "GBK");  

String keyValue = new String(rb.getString(keyName).getBytes("ISO-8859-1"), "GBK");

 

2.解決方法二:將machine_zh_CN.properties轉換成為unicode形式

native2ascii.exe machine_zh_CN.properties machine_zh_CN.txt

p1=/u51b0/u7bb1 p2=/u6d17/u8863/u673a p3=/u7535/u89c6/u673a


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM