Javatpoint Logo
Javatpoint Logo

Java URL toURI() method

The toURI() method returns URI equivalent to given URL. This method functions in the same way as new URI (this.toString()).

Syntax

Returns

A URI instance is equivalent to this URL.

Throw

URISyntaxException - if this URL is not formatted strictly according to RFC2396 and cannot be converted to a URI.

Since

1.5

Example 1

Test it Now

Output:

URL created: https://www.javatpoint.com/URL-class
URI from URL: https://www.javatpoint.com/URL-class

Example 2

Output:

URL:file:/D:/Advancejava/UrlClass/file%20name%20with%20spaces.txt
URI:file:/D:/Advancejava/UrlClass/file%20name%20with%20spaces.txt
URL (no special character handling):file:/D:/Advancejava/UrlClass/file name with spaces.txt
Next TopicJava URL Class





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA