如果在不知道的情况下,想了解当前虚拟机支持的协议类型,那么可以参考本文。
本文的测试实验出自:
-
public class TestURLProtocol {
-
-
public static void main(String[] args) {
-
String host = "";
-
String file = "/index.html";
-
-
String[] schames = {"http", "https", "ftp", "mailto", "telnet", "file", "ldap", "gopher",
-
"jdbc", "rmi", "jndi", "jar", "doc", "netdoc", "nfs", "verbatim", "finger", "daytime", ""
-
+ "systemresource"};
-
for (int i= 0; i < schames.length; i++) {
-
try {
-
URL url = new URL(schames[i], host, file);
-
System.out.println(schames[i] + " is supported\r\n");
-
} catch (MalformedURLException e) {
-
// TODO Auto-generated catch block
-
-
e.printStackTrace();
-
System.out.println(schames[i] + " is not supported\r\n");
-
}
-
}
-
-
}
测试结果如下:
-
http is supported
-
-
https is supported
-
-
ftp is supported
-
-
mailto is supported
-
-
java.net.MalformedURLException: unknown protocol: telnet
-
at java.net.URL.<init>(URL.java:413)
-
at java.net.URL.<init>(URL.java:302)
-
at java.net.URL.<init>(URL.java:325)
-
at urlSample.TestURLProtocol.main(TestURLProtocol.java:17)
-
telnet is not supported
-
-
file is supported
-
-
java.net.MalformedURLException: unknown protocol: ldap
-
at java.net.URL.<init>(URL.java:413)
-
at java.net.URL.<init>(URL.java:302)
-
at java.net.URL.<init>(URL.java:325)ldap is not supported
-
-
gopher is not supported
-
-
jdbc is not supported
-
-
rmi is not supported
-
-
jndi is not supported
-
-
jar is supported
-
-
-
at urlSample.TestURLProtocol.main(TestURLProtocol.java:17)
-
java.net.MalformedURLException: unknown protocol: gopher
-
at java.net.URL.<init>(URL.java:413)
-
at java.net.URL.<init>(URL.java:302)
-
at java.net.URL.<init>(URL.java:325)
-
at urlSample.TestURLProtocol.main(TestURLProtocol.java:17)
-
java.net.MalformedURLException: unknown protocol: jdbc
-
at java.net.URL.<init>(URL.java:413)
-
at java.net.URL.<init>(URL.java:302)
-
at java.net.URL.<init>(URL.java:325)
-
at urlSample.TestURLProtocol.main(TestURLProtocol.java:17)
-
java.net.MalformedURLException: unknown protocol: rmi
-
at java.net.URL.<init>(URL.java:413)
-
at java.net.URL.<init>(URL.java:302)
-
at java.net.URL.<init>(URL.java:325)
-
at urlSample.TestURLProtocol.main(TestURLProtocol.java:17)
-
java.net.MalformedURLException: unknown protocol: jndi
-
at java.net.URL.<init>(URL.java:413)
-
at java.net.URL.<init>(URL.java:302)
-
at java.net.URL.<init>(URL.java:325)
-
at urlSample.TestURLProtocol.main(TestURLProtocol.java:17)
-
java.net.MalformedURLException: unknown protocol: doc
-
at java.net.URL.<init>(URL.java:413)
-
at java.net.URL.<init>(URL.java:302)
-
at java.net.URL.<init>(URL.java:325)
-
at urlSample.TestURLProtocol.main(TestURLProtocol.java:17)
-
doc is not supported
-
-
netdoc is supported
-
-
java.net.MalformedURLException: unknown protocol: nfs
-
at java.net.URL.<init>(URL.java:413)
-
at java.net.URL.<init>(URL.java:302)
-
at java.net.URL.<init>(URL.java:325)
-
at urlSample.TestURLProtocol.main(TestURLProtocol.java:17)
-
nfs is not supported
-
-
java.net.MalformedURLException: unknown protocol: verbatim
-
at java.net.URL.<init>(URL.java:413)
-
at java.net.URL.<init>(URL.java:302)
-
at java.net.URL.<init>(URL.java:325)
-
at urlSample.TestURLProtocol.main(TestURLProtocol.java:17)
-
verbatim is not supported
-
-
java.net.MalformedURLException: unknown protocol: finger
-
at java.net.URL.<init>(URL.java:413)
-
at java.net.URL.<init>(URL.java:302)
-
at java.net.URL.<init>(URL.java:325)
-
at urlSample.TestURLProtocol.main(TestURLProtocol.java:17)
-
finger is not supported
-
-
java.net.MalformedURLException: unknown protocol: daytime
-
at java.net.URL.<init>(URL.java:413)
-
at java.net.URL.<init>(URL.java:302)
-
at java.net.URL.<init>(URL.java:325)
-
at urlSample.TestURLProtocol.main(TestURLProtocol.java:17)
-
daytime is not supported
-
-
java.net.MalformedURLException: unknown protocol: systemresource
-
at java.net.URL.<init>(URL.java:413)
-
at java.net.URL.<init>(URL.java:302)
-
at java.net.URL.<init>(URL.java:325)
-
at urlSample.TestURLProtocol.main(TestURLProtocol.java:17)
-
systemresource is not supported
阅读(654) | 评论(0) | 转发(0) |