我用这段代码在Java中创建URI:
new URI(/*scheme*/ "scheme", /*host*/ null, /*path*/ "/42", /*fragment*/ null);
当我将此URI转换为字符串时,我得到scheme:/42
。格式为scheme:/path
的URI是否有效?
当我使用new URI("scheme", "", "/path", null)
时,我得到了scheme:///path
。我知道这是有效的(如file:///
URI)。这些URI有不同的含义吗?
见Wikipedia article on URI和diagram on Wikimedia Commons:
URI = scheme:[//authority]path[?query][#fragment]
[…]
可以跳过//authority
(用户+密码+主机+端口)部分。 path
组件包括在/
部分之后的//authority
。
此URI有效。