可解决android无法读取url中文图片等问题
public static String urlEncodeChinese(String url) {
try {
Matcher matcher = Pattern.compile("[\\u4e00-\\u9fa5]").matcher(url);
String tmp = "";
while (matcher.find()) {
tmp = matcher.group();
url = url.replaceAll(tmp, URLEncoder.encode(tmp, "UTF-8"));
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return url;
}
public static void main(String[] args) {
String url = "http://localhost/中文.jpg";
System.out.println(urlEncodeChinese(url));
}