Encode String to UTF-8

后端 未结 11 1947
忘掉有多难
忘掉有多难 2020-11-22 08:33

I have a String with a \"ñ\" character and I have some problems with it. I need to encode this String to UTF-8 encoding. I have tried it by this way, but it doesn\'t work:

11条回答
  •  忘掉有多难
    2020-11-22 09:13

    You can try this way.

    byte ptext[] = myString.getBytes("ISO-8859-1"); 
    String value = new String(ptext, "UTF-8"); 
    

提交回复
热议问题