对有中文的URL进行URL编码转换

String encode(String url)
{
	Matcher matcher = Pattern.compile("[\\u4e00-\\u9fa5]").matcher(url);
	while(matcher.find())
	{
		String tmp = matcher.group();
		try
		{
			url = url.replaceAll(tmp, URLEncoder.encode(tmp, "gbk"));
		}
		catch (UnsupportedEncodingException e)
		{
			e.printStackTrace();
		}
	}
	return url;
}

你可能感兴趣的:(String,url)