Practical No. 15
Practical No. 15
15
1. Display the parts of a URL
import java.net.*;
public class Test {
public static void main(String[] args) {
try {
URI uri = new URI("http", "www.yahoo.com", "/index", null);
URL hp = uri.toURL();
System.out.println(hp.getProtocol());
System.out.println(hp.getPath());
System.out.println(hp.getHost());
System.out.println(hp.getFile());
System.out.println(hp.getPort());
} catch (URISyntaxException | MalformedURLException e) {
System.out.println(e); Output:
}
}
}