java将中文Url转换为浏览器识别的编码
java将中文Url转换为浏览器识别的编码
用到了URLEncoder.encode
解码的话用到 URLDecoder
代码如下:
public static String changeHanzi(String url) { char[] tp = url.toCharArray(); String now = ""; for (char ch : tp) { if (ch >= 0x4E00 && ch <= 0x9FA5) { try { now += URLEncoder.encode(ch + "", "gbk"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { now += ch; } } return now; }