Chinaunix首页 | 论坛 | 博客
  • 博客访问: 40806
  • 博文数量: 28
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 0
  • 用 户 组: 普通用户
  • 注册时间: 2015-04-17 11:05
文章分类
文章存档

2015年(28)

我的朋友

分类: Java

2015-04-20 18:54:21

如果在不知道的情况下,想了解当前虚拟机支持的协议类型,那么可以参考本文。
本文的测试实验出自:

点击(此处)折叠或打开

  1. public class TestURLProtocol {

  2.     public static void main(String[] args) {
  3.         String host = "";
  4.         String file = "/index.html";
  5.         
  6.         String[] schames = {"http", "https", "ftp", "mailto", "telnet", "file", "ldap", "gopher",
  7.                  "jdbc", "rmi", "jndi", "jar", "doc", "netdoc", "nfs", "verbatim", "finger", "daytime", ""
  8.                         + "systemresource"};
  9.         for (int i= 0; i < schames.length; i++) {
  10.             try {
  11.                 URL url = new URL(schames[i], host, file);
  12.                 System.out.println(schames[i] + " is supported\r\n");
  13.             } catch (MalformedURLException e) {
  14.                 // TODO Auto-generated catch block

  15.                 e.printStackTrace();
  16.                 System.out.println(schames[i] + " is not supported\r\n");
  17.             }
  18.         }

  19.     }
测试结果如下:

点击(此处)折叠或打开

  1. http is supported

  2. https is supported

  3. ftp is supported

  4. mailto is supported

  5. java.net.MalformedURLException: unknown protocol: telnet
  6.     at java.net.URL.<init>(URL.java:413)
  7.     at java.net.URL.<init>(URL.java:302)
  8.     at java.net.URL.<init>(URL.java:325)
  9.     at urlSample.TestURLProtocol.main(TestURLProtocol.java:17)
  10. telnet is not supported

  11. file is supported

  12. java.net.MalformedURLException: unknown protocol: ldap
  13.     at java.net.URL.<init>(URL.java:413)
  14.     at java.net.URL.<init>(URL.java:302)
  15.     at java.net.URL.<init>(URL.java:325)ldap is not supported

  16. gopher is not supported

  17. jdbc is not supported

  18. rmi is not supported

  19. jndi is not supported

  20. jar is supported


  21.     at urlSample.TestURLProtocol.main(TestURLProtocol.java:17)
  22. java.net.MalformedURLException: unknown protocol: gopher
  23.     at java.net.URL.<init>(URL.java:413)
  24.     at java.net.URL.<init>(URL.java:302)
  25.     at java.net.URL.<init>(URL.java:325)
  26.     at urlSample.TestURLProtocol.main(TestURLProtocol.java:17)
  27. java.net.MalformedURLException: unknown protocol: jdbc
  28.     at java.net.URL.<init>(URL.java:413)
  29.     at java.net.URL.<init>(URL.java:302)
  30.     at java.net.URL.<init>(URL.java:325)
  31.     at urlSample.TestURLProtocol.main(TestURLProtocol.java:17)
  32. java.net.MalformedURLException: unknown protocol: rmi
  33.     at java.net.URL.<init>(URL.java:413)
  34.     at java.net.URL.<init>(URL.java:302)
  35.     at java.net.URL.<init>(URL.java:325)
  36.     at urlSample.TestURLProtocol.main(TestURLProtocol.java:17)
  37. java.net.MalformedURLException: unknown protocol: jndi
  38.     at java.net.URL.<init>(URL.java:413)
  39.     at java.net.URL.<init>(URL.java:302)
  40.     at java.net.URL.<init>(URL.java:325)
  41.     at urlSample.TestURLProtocol.main(TestURLProtocol.java:17)
  42. java.net.MalformedURLException: unknown protocol: doc
  43.     at java.net.URL.<init>(URL.java:413)
  44.     at java.net.URL.<init>(URL.java:302)
  45.     at java.net.URL.<init>(URL.java:325)
  46.     at urlSample.TestURLProtocol.main(TestURLProtocol.java:17)
  47. doc is not supported

  48. netdoc is supported

  49. java.net.MalformedURLException: unknown protocol: nfs
  50.     at java.net.URL.<init>(URL.java:413)
  51.     at java.net.URL.<init>(URL.java:302)
  52.     at java.net.URL.<init>(URL.java:325)
  53.     at urlSample.TestURLProtocol.main(TestURLProtocol.java:17)
  54. nfs is not supported

  55. java.net.MalformedURLException: unknown protocol: verbatim
  56.     at java.net.URL.<init>(URL.java:413)
  57.     at java.net.URL.<init>(URL.java:302)
  58.     at java.net.URL.<init>(URL.java:325)
  59.     at urlSample.TestURLProtocol.main(TestURLProtocol.java:17)
  60. verbatim is not supported

  61. java.net.MalformedURLException: unknown protocol: finger
  62.     at java.net.URL.<init>(URL.java:413)
  63.     at java.net.URL.<init>(URL.java:302)
  64.     at java.net.URL.<init>(URL.java:325)
  65.     at urlSample.TestURLProtocol.main(TestURLProtocol.java:17)
  66. finger is not supported

  67. java.net.MalformedURLException: unknown protocol: daytime
  68.     at java.net.URL.<init>(URL.java:413)
  69.     at java.net.URL.<init>(URL.java:302)
  70.     at java.net.URL.<init>(URL.java:325)
  71.     at urlSample.TestURLProtocol.main(TestURLProtocol.java:17)
  72. daytime is not supported

  73. java.net.MalformedURLException: unknown protocol: systemresource
  74.     at java.net.URL.<init>(URL.java:413)
  75.     at java.net.URL.<init>(URL.java:302)
  76.     at java.net.URL.<init>(URL.java:325)
  77.     at urlSample.TestURLProtocol.main(TestURLProtocol.java:17)
  78. systemresource is not supported


阅读(654) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~