在 Android 中检查 URL 是否有效而不捕获异常?
看,我必须检查 50 多个 URL 的有效性,并且我假设捕获超过 50 个异常有点过分了。有没有一种方法可以检查一堆 URL 是否有效,而不用将其包装在 try catch 中来捕获异常?另外,仅供参考,在Android中,类“UrlValidator”不存在(但它确实存在于标准java中),并且有UrlUtil.isValidUrl(String url),但该方法似乎对您扔给它的任何内容感到满意只要它包含http://...有什么建议吗?
See, I have to check like 50+ URLs for validity, and I'm assuming that catching more than 50 exceptions is kind of over the top. Is there a way to check if a bunch of URLs are valid without wrapping it in a try catch to catch exceptions? Also, just fyi, in Android the class "UrlValidator" doesn't exist (but it does exist in the standard java), and there's UrlUtil.isValidUrl(String url) but that method seems to be pleased with whatever you throw at it as long as it contains http://... any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此解决方案确实捕获异常,但其他人可能会发现它很有用并且不需要任何库。
This solution does catch exceptions, however others may find it useful and doesn't require any libraries.