How to handle Arabic in java

后端 未结 2 500
无人及你
无人及你 2021-01-26 12:15

i need to pass a string of arabic value to the HttpURL as a parameter but before i do say when i print the message its showing only question marks

public void s         


        
2条回答
  •  一个人的身影
    2021-01-26 12:55

    Assuming that SendSms.getMessage() returns a String, what did you intend with this line?

    String message = new String(object.getMessage().getBytes(), "UTF-8");
    

    Encoding and decoding the message is a waste at best—if it works, you will just get back the string you started with. And it will only work if the default encoding is UTF-8. In this case, it's corrupting the message.

    When you encode a String with getBytes(), the platform default encoding is used. Unless the system's native character set supports Arabic, any Arabic character will be replaced with a supported character, usually ?.

    Try this instead:

    String message = object.getMessage();
    

提交回复
热议问题