52,797
社区成员
发帖
与我相关
我的任务
分享
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
public class ChineseToUTF8 {
public static String Encode(String chinese) throws UnsupportedEncodingException
{
String newStr = URLEncoder.encode( chinese, "utf8");
return newStr;
}
public static String Decode(String utf8) throws UnsupportedEncodingException
{
String newStr = URLDecoder.decode( utf8, "utf8");
return newStr;
}
public static void main(String[] args) throws UnsupportedEncodingException {
System.out.println(Encode("分辨率"));
System.out.println(Decode(Encode("分辨率")));
}
}
%E5%88%86%E8%BE%A8%E7%8E%87
分辨率
String str = "哥只是个传说";
String str1 = new String(str.getBytes("utf-8"),"gbk");
System.out.println("-------------" + str1);
String str2 = new String(str1.getBytes("GBK"),"utf-8");
System.out.println("-------------" + str2);