The library method does not work at this URL:
"http://en.wikipedia.org/wiki/3,2,1..._Frankie_Go_Boom"
Which is a perfectly legitimate ([and existing) URL (try it, the StackOverflow dialog didn't accept it, but if you copy it to your browser, you will see the Wikipedia page)
As a result of trial and error, I found that the code below is more accurate:
public static boolean isValidURL(String url) { URL u = null; try { u = new URL(url); } catch (MalformedURLException e) { return false; } try { u.toURI(); } catch (URISyntaxException e) { return false; } return true; }
source share