将中文转换成URL编码
将中文转换成URL编码的方法
public static String Encode(String str, String charset) { //将中文转换成URL编码
??? Pattern p = Pattern.compile("[\u4e00-\u9fa5]|\\u201c|\\u201d");
??? Matcher m = p.matcher(str);
??? StringBuffer b = new StringBuffer();
??? while (m.find()) {
????? try {
??????? m.appendReplacement(b, URLEncoder.encode(m.group(), charset));
????? }
????? catch (UnsupportedEncodingException ex) {
??????? ex.printStackTrace();
????? }
??? }
??? m.appendTail(b);
??? return b.toString();
? }