我正在編程將中文字符串轉換爲字節數組和字節數組轉換爲中文字符串。 我知道在使用UTF-8編碼時,中文字符串返回2個字節。 但它在我的電腦中返回3個字節。如何將中文字符串轉換爲字節數組和字節數組爲中文字符串?
//test code
String result = System.getProperty("file.encoding"); // UTF-8
String temp = new String("中國");
byte[] bytes = temp.getBytes();
結果:
字節= {-28,-72,-83,-27,-101,-67}
但我don'k熟悉。 請幫幫我。謝謝
'我知道什麼時候使用UTF-8編碼,中文字符串返回2個字節的來源? – njzk2