Encode String to UTF-8

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

    A Java String is internally always encoded in UTF-16 - but you really should think about it like this: an encoding is a way to translate between Strings and bytes.

    So if you have an encoding problem, by the time you have String, it's too late to fix. You need to fix the place where you create that String from a file, DB or network connection.

提交回复
热议问题