public static String encode(String str, String charset) throws UnsupportedEncodingException { Pattern p = Pattern.compile("[u4e00-u9fa5]+"); Matcher m = p.matcher(str); StringBuffer b = new StringBuffer(); while (m.find()) { m.appendReplacement(b, URLEncoder.encode(m.group(0), charset)); } m.appendTail(b); return b.toString(); }