将URL中的中文转为UTF8编码

       
 1  /**
 2    * 将URL中的中文转为UTF-8编码
 3    * @param str
 4    * @return
 5    * @throws UnsupportedEncodingException
 6    */
 7   public String utfURL(String str) throws UnsupportedEncodingException{
 8   StringBuffer sb = new StringBuffer();
 9    int len = str.length();
10           for (int i = 0; i < len; i++) {
11               char c = str.charAt(i);
12                   if (c > 0x7F) {
13                   sb.append(URLEncoder.encode(String.valueOf(c),"utf-8"));
14                   }else {
15                   sb.append(c);
16                   }
17           }
18          return sb.toString();
19   }
原文地址:https://www.cnblogs.com/icoding/p/2581158.html