Java 字符轉碼之UTF-8轉爲GBK/GB2312

定義一字符串:

String t = "hfjkds中國中國中國中國中國中國中國中國中國中國中國中國中國中國中國中國中國中國中國中國hfsdkj<img src='sasa' /> fjldsajflkdsjaflkdsjalf <img src='sada' ait=''/>sfdsfadas";
思路:先轉爲Unicode,然後轉爲GBK

			String utf8 = new String(t.getBytes( "UTF-8"));
			System.out.println(utf8);
			String unicode = new String(utf8.getBytes(),"UTF-8"); 
			System.out.println(unicode);
			String gbk = new String(unicode.getBytes("GBK"));
			
			System.out.println(gbk);


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章