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

版权声明:本文为博主原创文章,请多指教,转载请注明出处 https://blog.csdn.net/newairzhang/article/details/73801666

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();

展开阅读全文

没有更多推荐了,返回首页