1. 程式人生 > >String字串,轉碼UTF-8

String字串,轉碼UTF-8

String str = "任意字串";
str = new String(str.getBytes("gbk"),"utf-8");

備註說明:
str.getBytes("UTF-8"); 的意思是以UTF-8的編碼取得位元組 
new String(XXX,"UTF-8"); 的意思是以UTF-8的編碼生成字串

注意要try   catch