汉字转GBK编码
(2017-10-23 10:57:27)分类: 服务器开发 |
public static String toGBK(String source) throws UnsupportedEncodingException {
StringBuilder sb = new StringBuilder();
byte[] bytes = source.getBytes("GBK");
for(byte b : bytes) {
sb.append("%" + Integer.toHexString((b & 0xff)).toUpperCase());
}
return sb.toString();
}
//////////////////
URLDecoder.decode(str,"utf-8") //解码
URLEncoder.encode(CityName.mCityName[i],"GBK")//转码
前一篇:反射机制调用部分方法
后一篇:使用Jsoup快速拆解网页内容