Java URL(String protocol, String host, int port, String file) Constructor
Syntax
URL(String protocol, String host, int port, String file) constructor from URL has the following syntax.
public URL(String protocol, String host, int port, String file) throws MalformedURLException
Example
In the following code shows how to use URL.URL(String protocol, String host, int port, String file) constructor.
import java.net.URL;
/* w w w. jav a 2 s .c o m*/
public class Main {
public static void main(String[] argv) throws Exception {
URL url = new URL("http", "hostname", 80, "index.html");
System.out.println(url);
}
}
The code above generates the following result.