src/java.base/share/classes/java/net/package-info.java

Print this page




 126  * <p>The recommended usage is to use {@link java.net.URI} to identify
 127  *    resources, then convert it into a {@link java.net.URL} when it is time to
 128  *    access the resource. From that URL, you can either get the
 129  *    {@link java.net.URLConnection} for fine control, or get directly the
 130  *    InputStream.
 131  * <p>Here is an example:</p>
 132  * <pre>
 133  * URI uri = new URI("http://java.sun.com/");
 134  * URL url = uri.toURL();
 135  * InputStream in = url.openStream();
 136  * </pre>
 137  * <h2>Protocol Handlers</h2>
 138  * As mentioned, URL and URLConnection rely on protocol handlers which must be
 139  * present, otherwise an Exception is thrown. This is the major difference with
 140  * URIs which only identify resources, and therefore don't need to have access
 141  * to the protocol handler. So, while it is possible to create an URI with any
 142  * kind of protocol scheme (e.g. {@code myproto://myhost.mydomain/resource/}),
 143  * a similar URL will try to instantiate the handler for the specified protocol;
 144  * if it doesn't exist an exception will be thrown.
 145  * <p>By default the protocol handlers are loaded dynamically from the default
 146  *    location. It is, however, possible to add to the search path by setting
 147  *    the {@code java.protocol.handler.pkgs} system property. For instance if
 148  *    it is set to {@code myapp.protocols}, then the URL code will try, in the
 149  *    case of http, first to load {@code myapp.protocols.http.Handler}, then,
 150  *    if this fails, {@code http.Handler} from the default location.
 151  * <p>Note that the Handler class <b>has to</b> be a subclass of the abstract
 152  *    class {@link java.net.URLStreamHandler}.</p>
 153  * <h2>Additional Specification</h2>
 154  * <ul>
 155  *       <li><a href="doc-files/net-properties.html">
 156  *            Networking System Properties</a></li>
 157  * </ul>
 158  *
 159  * @since 1.0
 160  */
 161 package java.net;


 126  * <p>The recommended usage is to use {@link java.net.URI} to identify
 127  *    resources, then convert it into a {@link java.net.URL} when it is time to
 128  *    access the resource. From that URL, you can either get the
 129  *    {@link java.net.URLConnection} for fine control, or get directly the
 130  *    InputStream.
 131  * <p>Here is an example:</p>
 132  * <pre>
 133  * URI uri = new URI("http://java.sun.com/");
 134  * URL url = uri.toURL();
 135  * InputStream in = url.openStream();
 136  * </pre>
 137  * <h2>Protocol Handlers</h2>
 138  * As mentioned, URL and URLConnection rely on protocol handlers which must be
 139  * present, otherwise an Exception is thrown. This is the major difference with
 140  * URIs which only identify resources, and therefore don't need to have access
 141  * to the protocol handler. So, while it is possible to create an URI with any
 142  * kind of protocol scheme (e.g. {@code myproto://myhost.mydomain/resource/}),
 143  * a similar URL will try to instantiate the handler for the specified protocol;
 144  * if it doesn't exist an exception will be thrown.
 145  * <p>By default the protocol handlers are loaded dynamically from the default
 146  *    location. It is, however, possible to deploy additional protocols handlers
 147  *    as {@link java.util.ServiceLoader services}. Service providers of type
 148  *    {@code URLStreamHandlerFactory} are located at runtime, as specified in
 149  *    the {@linkplain java.net.URL#URL(String,String,int,String) URL constructor}.



 150  * <h2>Additional Specification</h2>
 151  * <ul>
 152  *       <li><a href="doc-files/net-properties.html">
 153  *            Networking System Properties</a></li>
 154  * </ul>
 155  *
 156  * @since 1.0
 157  */
 158 package java.net;