Encode String to UTF-8

后端 未结 11 1806
忘掉有多难
忘掉有多难 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:06

    String objects in Java use the UTF-16 encoding that can't be modified.

    The only thing that can have a different encoding is a byte[]. So if you need UTF-8 data, then you need a byte[]. If you have a String that contains unexpected data, then the problem is at some earlier place that incorrectly converted some binary data to a String (i.e. it was using the wrong encoding).

提交回复
热议问题