操作系统默认编码:UTF-8
在python中将UTF-8 str转换为UTF-16:
utf8_str = "Hélô" # type(utf8_str) is str and encoded in UTF-8
unicode_str = utf8_str.decode("UTF-8") # type(unicode_str) is unicode
utf16_str = unicode_str.encode("UTF-16") #type(utf16_str) is str and encoded in UTF-16
正如你所看到的,unicode是将utf-8 str转换为utf-16 str的桥梁,它很容易理解。
但是,在java中,我对转换感到困惑:
String utf16Str = "Hélô";// String encoded in "UTF-16"
byte[] bytes = utf16Str.getBytes("UTF-8");//byte array encoded in UTF-8, getBytes will call a encode method.
String newUtf16Str = new String(bytes, "UTF-8");// String encoded in "UTF-16"
没有解码,没有unicode。那么,在这个过程中发生了什么?