How to use UTF-8 in resource properties with ResourceBundle

后端 未结 16 2491
难免孤独
难免孤独 2020-11-22 03:28

I need to use UTF-8 in my resource properties using Java\'s ResourceBundle. When I enter the text directly into the properties file, it displays as mojibake.

16条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-22 03:36

    Given that you have an instance of ResourceBundle and you can get String by:

    String val = bundle.getString(key); 
    

    I solved my Japanese display problem by:

    return new String(val.getBytes("ISO-8859-1"), "UTF-8");
    

提交回复
热议问题