汉字转GBk
程序员文章站
2022-05-25 08:01:38
...
//汉字转GBK
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();
}