This class represents a uniform resource locator and allows the data referred to by the URL to be downloaded. A URL can be specified as a single string or with separate protocol, host, port, and file specifications. Relative URLs can also be specified with a String and the URL object to which it is relative. getFile( ) , getHost( ) , getProtocol( ) and related methods return the various portions of the URL specified by a URL object. sameFile( ) determines whether a URL object refers to the same file as this one. getdefaultPort( ) returns the default port number for the protocol of the URL object; it may differ from the number returned by getPort( ) . Use openConnection( ) to obtain a URLConnection object with which you can download the content of the URL. In Java 5.0, you can explicitly specify a Proxy object through which the connection should be opened. For simple cases, however, the URL class defines shortcut methods that create and invoke methods on a URLConnection internally. getContent( ) downloads the URL data and parses it into an appropriate Java object (such as a string or image) if an appropriate ContentHandler can be found. In Java 1.3 and later, you can pass an array of Class objects that specify the type of objects that you are willing to accept as the return value of this method. If you wish to parse the URL content yourself, call openStream( ) to obtain an InputStream from which you can read the data. Figure 12-27. java.net.URLpublic final class URL implements Serializable { // Public Constructors public URL (String spec ) throws MalformedURLException; public URL (URL context , String spec ) throws MalformedURLException; 1.2 public URL (URL context , String spec , URLStreamHandler handler ) throws MalformedURLException; public URL (String protocol , String host , String file ) throws MalformedURLException; public URL (String protocol , String host , int port , String file ) throws MalformedURLException; 1.2 public URL (String protocol , String host , int port , String file , URLStreamHandler handler ) throws MalformedURLException; // Public Class Methods public static void setURLStreamHandlerFactory (URLStreamHandlerFactory fac ); // Public Instance Methods 1.3 public String getAuthority ( ); public final Object getContent ( ) throws java.io.IOException; 1.3 public final Object getContent (Class[ ] classes ) throws java.io.IOException; 1.4 public int getDefaultPort ( ); public String getFile ( ); public String getHost ( ); 1.3 public String getPath ( ); public int getPort ( ); public String getProtocol ( ); 1.3 public String getQuery ( ); public String getRef ( ); 1.3 public String getUserInfo ( ); public URLConnection openConnection ( ) throws java.io.IOException; 5.0 public URLConnection openConnection (java.net.Proxy proxy ) throws java.io.IOException; public final java.io.InputStream openStream ( ) throws java.io.IOException; public boolean sameFile (URL other ); public String toExternalForm ( ); 5.0 public URI toURI ( ) throws URISyntaxException; // Public Methods Overriding Object public boolean equals (Object obj ); public int hashCode ( ); synchronized public String toString ( ); // Protected Instance Methods protected void set (String protocol , String host , int port , String file , String ref ); 1.3 protected void set (String protocol , String host , int port , String authority , String userInfo , String path , String query , String ref ); } Passed ToToo many methods to list. Returned Byjava.io.File.toURL( ) , Class.getResource( ) , ClassLoader.{findResource( ) , getresource( ) , getSystemResource( )} , Authenticator.getRequestingURL( ) , JarURLConnection.getJarFileURL( ) , URI.toURL( ) , URLClassLoader.{findResource( ) , getURLs( )} , URLConnection.getURL( ) , java.security.CodeSource.getLocation( ) Type OfURLConnection.url |