Sorry for asking basic questions here. Pardon me.
I have a sequence a string in this in unicode as follows.
String unicode = "\u8BF7\u5728\u6B64\u5904\u8F93\u5165\u4EA7\u54C1\u7F16\u53F7\u6216\u540D\u79F0";
How can I convert this to Chinese text or the UTF-8 text ?
The String itself will always be in Unicode; I’m not sure what you mean by “convert this to Chinese text” but to convert it to the binary representation using UTF-8 you’d use:
or you can use the
Charset– using the Guava library for example, you’d just use:(This gets round the brittleness of specifying a string, and avoids worrying about catching
UnsupportedEncodingException.)Or you can declare:
at the top of your class to avoid a whole library as a cure for the string.