Java URL toURI() method24 Mar 2025 | 1 min read The toURI() method returns URI equivalent to given URL. This method functions in the same way as new URI (this.toString()). SyntaxReturnsA URI instance is equivalent to this URL. ThrowURISyntaxException - if this URL is not formatted strictly according to RFC2396 and cannot be converted to a URI. Since1.5 Example 1Output: URL created: https://www.tpointtech.com/URL-class URI from URL: https://www.tpointtech.com/URL-class Example 2Output: 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 |
Java Method The getRef() method of URL class returns the anchor(reference) of the URL or the null if not exist . Syntax public String getRef() Returns The anchor (also known as the "reference") of this URL, or null if one does not exist Example 1 import java.io.*; import java.net.*; class URLGetRefExample1 { public static...
1 min read
Java Method The equals() method of URL class compares this URL for equality with another URL object. It returns false if the given object is not a URL. If IP address of two different is same, then it considered equivalent host. Syntax public boolean equals(Object obj) Overrides equals in...
1 min read
Java Method The toString() method of URL class constructs a string representation of this URL. The string is created by calling the toExternalFile() method of the stream protocol handler for this object. Syntax public String toString() Overrides toString in class Object Returns A string representation of this object. Example 1 import java.net.*; public class...
1 min read
Java Method The openConnection() method of URL class opens the connection to specified URL and URLConnection instance that represents a connection to the remote object referred by the URL. It should be noted that a URLConnection instance does not establish the actual network connection on the...
3 min read
Java Method The getHost() method of URL class returns the hostname of the URL. This method will return the IPv6 address enclosed in square brackets ('['and']'). Syntax public String getHost() Parameter NA Returns the hostname of this URL. Example 1 import java.net.URL; import java.util.Scanner; public class URLgetHostExample1{ public static void main(String args[])throws Exception { //passing url in constructor URL...
1 min read
Java URL class getDefaultPort() Method The getDefaultPort() method of URL class is used to get the default port number of the protocol associated with given URL. If the URL scheme or the URLStreamHandler for the URL does not define a default port number, then -1 is...
1 min read
Java Method The getProtocol() Method of URL class returns the protocol name of this URL. Syntax public String getProtocol() Returns The protocol of this URL. Example 1 import java.net.URL; import java.util.Scanner; public class UrlgetProtocolExample1 { public static void main(String args[])throws Exception { //passing url in constructor URL url1=new URL("https://www.tpointtech.com/URL-class"); System.out.println("Url: "+url1); // Getting protocal used in given url System.out.println("Protocol...
1 min read
Java Method The getContent() Method of URL gets the contents of this URL. This method is a shorthand for openConnection().getContent(). Syntax public final Object getContent() throws IOException Returns The contents of this URL. Throw IOException - if an I/O exception occurs. Example 1 import java.net.URL; import java.util.Scanner; public class UrlGetContentExample1{ public static void main(String args[])throws...
1 min read
Java Method The getPath() method of URL class is used to get the path part of this URL. It returns an empty string if one does not exist. Syntax public String getPath() Returns The path part of this URL, or an empty string if one does not exist Since 1.3 Example 1 import...
1 min read
Java Method The getUserInfo() method of URL class returns the userInfo part of this URL in the form of the string. If the user information is not available, it returns null. Syntax public String getUserInfo() Returns The userInfo part of this URL, or null if one does not exist Since 1.3 Example...
1 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India