import java.net.*;
public class getURLParts {
public static void main(String args[]) {
for (int i = 0; i < args.length; i++) {
try {
URL u = new URL(args[0]);
System.out.println("The URL is " + u);
System.out.println("The protocol part is " + u.getProtocol());
System.out.println("The host part is " + u.getHost());
System.out.println("The port part is " + u.getPort());
System.out.println("The file part is " + u.getFile());
System.out.println("The ref part is " + u.getRef());
} // end try
catch (MalformedURLException e) {
System.err.println(args[0] + "is not a URL I understand.");
}
} // end for
} // end main
} // end getURLParts
|