Explain how to make a connection to a URL

Explain how to make a connection to a URL

Connection to the remote object represented by the URL is only initiated when the connect() method of the URLConnection is called. Doing this initializes a communication link between your Java program and the URL over the network.

The following code show how a connection to a URL is made.
try
{
   URL xyz = new URL(http://www.xyz.com/);
   URLConnection xyzConnection = xyz.openConnection();
   xyzConnection.connect();
}

catch (MalformedURLException e)
{
   // new URL() failed
   . . .
}
catch (IOException e)
{
    // openConnection() failed
   . . .
}
Explain how to read from a remote file when we have its URL
How to read from a remote file when we have its URL - With the help of the following code you could directly read from the URL:...
What is Uniform Resource Identifier (URI)?
What is Uniform Resource Identifier (URI)? - A URI is in the form of a string of characters for the purpose of identifying an abstract or physical resource...
Java URL handling architecture
Java URL handling architecture - Java URL architecture is handled by the java.net.URL object instances. It is utilized to handle the URL string...
Post your comment