Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

find protocol corresponding to URI in Java

Tags:

People also ask

How do I find the URL protocol?

Just use String. startsWith("http://") to check this. You can use URL.

What is URI type in Java?

Represents a Uniform Resource Identifier (URI) reference. Aside from some minor deviations noted below, an instance of this class represents a URI reference as defined by RFC 2396: Uniform Resource Identifiers (URI): Generic Syntax, amended by RFC 2732: Format for Literal IPv6 Addresses in URLs.

What is URI and URL Java?

URI => Uniform Resource Identifier Identifies a complete address of resource i-e location, name or both. URL => Uniform Resource Locator Identifies location of the resource. URN => Uniform Resource Name Identifies the name of the resource. Example.

What does the Java net Uri present?

What is URI? URI stands for Uniform Resource Identifier. A Uniform Resource Identifier is a sequence of characters used for identification of a particular resource. It enables for the interaction of the representation of the resource over the network using specific protocols.


I have URI object in Java. I want to convert it to InputStream, but the conversion should depend on the protocol. I can make it this way if my URI is http://somepath.com/mysuperfile.xsl:

return myURI.toURL().openConnection().getInputStream();

or this way if my uri is file:///somepath/mysuperfile.xsl:

return new FileInputStream(Paths.get(myURI).toFile());

or maybe even some another way. I can try to check it manually, but do Java have some nice/proper way to check it, maybe using that new java.nio.* package?