URL编码转义,冒号和不转,否则导致http链接失效URL含有中⽂需要转义
参考 blog.csdn/benbenxiongyuan/article/details/10608095
⾃⼰写⼀个
1public boolean checkURLFileIsExist(String stringURL){
2boolean isExist = false;
3 String sEncodeURL;
4
5try{
6// URL内中⽂编码
7 String s2 = deURIComponent(stringURL, "UTF-8");
8// :和/都会被编码,导致http链接就会失效处理
9 sEncodeURL = s2.replaceAll("\\%3A", ":").replaceAll("\\%2F", "/");
10 URL url = new URL(sEncodeURL);
url编码处理11 HttpURLConnection conn = (HttpURLConnection) url.openConnection();
12int state = ResponseCode();
13if(state == 200){
14 isExist = true;
15 }else{
16 isExist = false;
17 }
18 }catch(Exception e){
19 ("checkURLFileIsExist occur exception:" + e);
20 isExist = false;
21return isExist;
22 }
23return isExist;
24 }
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论