Java: How to write “Arabic” in properties file?

前端 未结 7 1972
自闭症患者
自闭症患者 2021-01-05 09:32

I want to write \"Arabic\" in the message resource bundle (properties) file but when I try to save it I get this error:

\"Save couldn\'t be completed Some characters

7条回答
  •  北海茫月
    2021-01-05 10:18

    Besides native2ascii tool mentioned in other answers there is a java Open Source library that can provide conversion functionality to be used in code

    Library MgntUtils has a Utility that converts Strings in any language (including special characters and emojis to unicode sequence and vise versa:

    result = "Hello World";
    result = StringUnicodeEncoderDecoder.encodeStringToUnicodeSequence(result);
    System.out.println(result);
    result = StringUnicodeEncoderDecoder.decodeUnicodeSequenceToString(result);
    System.out.println(result);
    

    The output of this code is:

    \u0048\u0065\u006c\u006c\u006f\u0020\u0057\u006f\u0072\u006c\u0064
    Hello World
    

    The library can be found at Maven Central or at Github It comes as maven artifact and with sources and javadoc

    Here is javadoc for the class StringUnicodeEncoderDecoder

提交回复
热议问题