开发者

How to identify correct url

开发者 https://www.devze.com 2023-03-22 20:18 出处:网络
I have list of URL in txt file I am using it for perf开发者_StackOverflow中文版ormance test, since URL were not formed correctly java.IO.exeption were thrown,I would like to know how to check correctn

I have list of URL in txt file I am using it for perf开发者_StackOverflow中文版ormance test, since URL were not formed correctly java.IO.exeption were thrown,I would like to know how to check correctness of URL? and whether it is working fine? I have more than 35 K url checking manually will consume lot's of time.


To check whether URL are properly formed try casting the string to an URI object. eg:

public void validURLs(List<string> urlList)
{
   int line = 1;
   for(string s : urlList)
   {
      try 
      {
          URI test = new URI(s);
      }
      catch(Exception e)
      {
          System.err.println(s + " is not a valid URL, item " + line);
      }
      line ++;
   }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消