Difference between file URI and URL in java

The URI has two subsets like URL and URN ,   URI and URL  are not same . A URI  may be absolute or relative ,but the URL is absolute .




URI (Uniform Resource Identifier ) :

URI and URL It is a sequence of characters which is used to identify abstract or  physical resource .

URI is super set of both URL and URN  .


URL (Uniform Resource Locator) :

It includes location and also network protocol to retrieve the resource .

Every URL is a URI ,but every URI is not a URL .


URN (Uniform Resource Name) :

It is a persistent ,globally unique name assigned to an object .

URN has no location dependence like URL .

Every URN is a URI ,but every URI is not a URN .


URI and URL  Syntax:

URI <uriName> = <FileObject>.toURI();
URL <urlName> = <FileObject>.toURL();

Java example for URI and URL :

Execution Result:


toURL is a deprecated method . So get URI from abstract path name and convert to URL .



Related Posts :
   [will not be published]

^ <