开发者

How to identify correct url

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜