Just use String. startsWith("http://") to check this. You can use URL.
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.
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 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?
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