Skip to content

Instantly share code, notes, and snippets.

@rizafahmi
Created March 6, 2016 12:58
Show Gist options
  • Save rizafahmi/3805877ad2585dc50807 to your computer and use it in GitHub Desktop.
Save rizafahmi/3805877ad2585dc50807 to your computer and use it in GitHub Desktop.
Java Network Programming
import java.net.*;
public class ProtocolTester {
public static void main(String[] args) {
String url = "www.bl.ac.id";
testProtocol("http://" + url);
testProtocol("https://" + url);
testProtocol("ftp://" + url);
testProtocol("nfs://" + url);
testProtocol("telnet://" + url);
testProtocol("mailto:rizafahmi@gmail.com");
}
private static void testProtocol (String url) {
try {
URL u = new URL(url);
System.out.println(u.getProtocol() + " is supported.");
} catch (MalformedURLException e) {
String protocol = url.substring(0, url.indexOf(":"));
System.out.println(protocol + " is not supported");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment