Created
March 6, 2016 12:58
-
-
Save rizafahmi/3805877ad2585dc50807 to your computer and use it in GitHub Desktop.
Java Network Programming
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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:[email protected]"); | |
} | |
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