展开全部
方法一:62616964757a686964616fe4b893e5b19e31333335313762思路:先转为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);
方法二:public static void main(String[] args) {
String str="字符串编码转换";
try {
byte[] temp=str.getBytes("utf-8");//这里写原编码方式
byte[] newtemp=new String(temp,"utf-8").getBytes("gbk");//这里写转换后的编码方式
String newStr=new String(newtemp,"gbk");//这里写转换后的编码方式
System.out.println(newStr);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}