Even if this is an old post with an already accepted answer, I am posting my alternative answer because it is well suited for this problem and no one seems to mention this method.
With the java.net.URI library:
URI uri = URI.create(URLString);
And if you need the corresponding string in URL format:
String validURLString = uri.toASCIIString();
Unlike many other methods (e.g. java.net.URLEncoder), this replaces only unsafe ASCII characters (e.g. ç , é ...).
In the above example, if the URLString is the following String :
"http://www.domain.com/façon+word"
the resulting validURLString will be:
"http://www.domain.com/fa%C3%A7on+word"
which is a well formatted url.
dgiugg Aug 6 2018-12-14T00: 00Z
source share