HttpURLConnection无法打开含有中文的链接

HttpURLConnection无法打开含有中文的链接

方法:使用 URLEncoder
URLEncoder.encode(str, “utf-8”);

filepath = “http://localhost/movie/爱的发声练习.srt”

String srtname = filepath.substring(filepath.lastIndexOf(“/”) + 1);

filepath = filepath.substring(0,filepath.lastIndexOf(“/”))+
“/”+URLEncoder.encode(srtname,”utf-8”);

URL url = new URL(filepath);
HttpURLConnection conn = (HttpURLConnection) url
.openConnection();

你可能感兴趣的:(android开发进阶,HttpURL,中文)