一个Demo看URL和URI的区别
来源:互联网 发布:删除json数组指定元素 编辑:程序博客网 时间:2024/05/19 13:28
DEMO来自:http://blog.sina.com.cn/s/blog_621c16b101012itu.html
package com.practise.test;import java.net.MalformedURLException;import java.net.URI;import java.net.URISyntaxException;import java.net.URL;/** * Created by mashao on 15/11/27. */public class Main { public static void main(String[] args) { try { URL url=new URL("http://developer.android.com/referencejava/net/URL.html?s=a#getRef()"); System.out.println("Authority是:"+url.getAuthority()); System.out.println("Host是:"+url.getHost()); System.out.println("Port是:"+url.getPort()); System.out.println("File是"+url.getFile()); System.out.println("Path是"+url.getPath()); System.out.println("Query是:"+url.getQuery()); System.out.println("Ref是:"+url.getRef()); } catch (MalformedURLException e) { e.printStackTrace(); } try { URI absolute=new URI("http://www.baidu.com"); URI relative=new URI("robot.txt"); URI resolved=new URI("http://www.baidu.com/robot.txt"); System.out.println("-----------------------解析前-------------------------"); System.out.println("Authority是:"+relative.getAuthority()); System.out.println("Host是:"+relative.getHost()); System.out.println("Port是:"+relative.getPort()); System.out.println("Path是"+relative.getPath()); System.out.println("Query是:"+relative.getQuery()); System.out.println("Ref是:"+relative.getFragment()); System.out.println("Scheme是:"+relative.getScheme()); System.out.println("-----------------------解析后-------------------------"); relative=absolute.resolve(relative); System.out.println("Authority是:"+relative.getAuthority()); System.out.println("Host是:"+relative.getHost()); System.out.println("Port是:"+relative.getPort()); System.out.println("Path是"+relative.getPath()); System.out.println("Query是:"+relative.getQuery()); System.out.println("Ref是:"+relative.getFragment()); System.out.println("Scheme是:"+relative.getScheme()); System.out.println("-----------------------相对化-------------------------"); relative=absolute.relativize(resolved); System.out.println("Authority是:"+relative.getAuthority()); System.out.println("Host是:"+relative.getHost()); System.out.println("Port是:"+relative.getPort()); System.out.println("Path是"+relative.getPath()); System.out.println("Query是:"+relative.getQuery()); System.out.println("Ref是:"+relative.getFragment()); System.out.println("Scheme是:"+relative.getScheme()); System.out.println("-----------------------不透明-------------------------"); URI uri=new URI("mailto:warsh@msncn"); System.out.println("Authority是:"+uri.getAuthority()); System.out.println("Host是:"+uri.getHost()); System.out.println("Port是:"+uri.getPort()); System.out.println("Path是"+uri.getPath()); System.out.println("Query是:"+uri.getQuery()); System.out.println("Ref是:"+uri.getFragment()); System.out.println("Scheme是:"+uri.getScheme()); System.out.println("Scheme具体部分:"+uri.getSchemeSpecificPart()); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } }}
总结:URI是你给一个东西的标识的名字,而URL是你给这个东西的地址用来找到这样东西。
1 0
- 一个Demo看URL和URI的区别
- URI和URL的区别
- URI和URL的区别
- URI和URL的区别
- URI和URL的区别
- URI和URL的区别
- URI和URL的区别
- URI 和 URL的区别
- URI和URL的区别
- URL 和 URI 的区别
- URL和URI的区别
- URL和URI的区别
- URI和URL的区别
- URI和URL的区别
- URL和URI的区别
- URI和URL的区别
- URI和URL的区别
- URI和URL的区别
- 监理工程师岁月--杀人事件
- UIWindow探究
- C++中delete和delete[]的区别
- LeetCode 110 Balanced Binary Tree
- java调用kettle工具类
- 一个Demo看URL和URI的区别
- 各种排序算法的分析及java实现
- SpringMVC 注解
- java.lang.UnsupportedOperationException
- 11.27、12.4 实验
- 键盘return键的设置
- 7.3 直方图
- Mybatis_插入数据后返回主键ID_返回数据字段与类中字段相对应
- java格式化输出