URL编码转义,冒号和/不转,否则导致http链接失效

URL含有中文需要转义

参考 https://blog.csdn.net/benbenxiongyuan/article/details/10608095

自己写一个

 1 public boolean checkURLFileIsExist(String stringURL){
 2         boolean isExist = false;
 3         String sEncodeURL;
 4 
 5         try{
 6             // URL内中文编码
 7             String s2 = Utils.encodeURIComponent(stringURL, "UTF-8");
 8             // :和/都会被编码,导致http链接就会失效处理
 9             sEncodeURL = s2.replaceAll("\%3A", ":").replaceAll("\%2F", "/");
10             URL url = new URL(sEncodeURL);
11             HttpURLConnection conn = (HttpURLConnection) url.openConnection();
12             int state = conn.getResponseCode();
13             if(state == 200){
14                 isExist  = true;
15             }else{
16                 isExist  = false;
17             }
18         }catch(Exception e){
19             logger.error("checkURLFileIsExist occur exception:" + e);
20             isExist = false;
21             return isExist;
22         }
23         return isExist;
24     }
原文地址:https://www.cnblogs.com/zhangcheng1/p/11174736.html