我嘗試使用下面的方法來編碼在java中串串,中國字符區分UTF-16編碼在Java中
String s = "子";
byte[] bytesEncoded = Base64.encodeBase64(s.getBytes("UTF-16"));
String stringEncoded = new String(bytesEncoded);
當我在Eclipse中運行這段代碼我得到的值/ v9bUA ==
但是一些網上UTF-16轉換器給值一樣4E02
任何人都知道如何將中國的字符轉換爲UTF 16
我已經通過大部分的stackoverflow問題仍然沒有答案。
在此先感謝!
我認爲你應該添加ISO8859-1到你的字符串像:String string1 = new String(encoding1,「ISO8859-1」); –
聽起來像轉換器有一個錯誤,或者你濫用它。如果你不分享*你使用過哪種轉換器,任何人都很難複製你的結果,你不覺得嗎? – dimo414
另外'4E02'看起來像十六進制,而不是Base64。爲什麼你使用Base64編碼Java字符串? – dimo414