I have to change URL to URI, please guide me how can I change it.
I have tried a lot, but not getting the solution. Any help is appreciated. I can also attach code snippet if required.
A URI is a uniform resource identifier while a URL is a uniform resource locator.
Use URLUtil to validate the URL as below. It will return True if URL is valid and false if URL is invalid.
We can parse any URL using Uri.parse(String) method.
Code Snippet :
Uri uri = Uri.parse( "http://www.stackoverflow.com" );
final String myUrlStr = "xyz"; URL url; Uri uri; try { url = new URL(myUrlStr); uri = Uri.parse( url.toURI().toString() ); } catch (MalformedURLException e1) { e1.printStackTrace(); } catch (URISyntaxException e) { e.printStackTrace(); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With