[英]Why would aFile.toURI().toString() on linux have a single slash?
What is the deal with Java's bizarre file protocol handling? Java奇怪的文件协议处理有什么用? I mean on windows UNC path's get turned into 5 slashes, and I get why that happens, but on linux an absolute path gets turned into
file:/local/path/to/file
Shouldn't that have three slashes? 我的意思是在Windows上UNC路径变成了5个斜杠,我明白为什么会发生这种情况,但是在linux上,绝对路径变成了
file:/local/path/to/file
不应该有三个斜杠吗? I'm assuming the authors of Java aren't incompetent, so is there an explanation for why that's acceptable? 我假设Java的作者并不称职,那么为什么这是可以接受的呢?
Let's start with the documentation of the URI class : 让我们从URI类的文档开始:
A hierarchical URI is subject to further parsing according to the syntax
分层URI根据语法进行进一步解析
[ scheme
:
][//
authority ][ path ][?
[ scheme
:
] [//
权限 ] [ 路径 ] [?
query ][#
fragment ]查询 ] [
#
片段 ]
As you can see, the authority is optional. 如您所见,权限是可选的。 This is supported by the URI specification, section 3 :
这支持URI规范,第3节 :
The scheme and path components are required, though the path may be empty (no characters).
方案和路径组件是必需的,但路径可能为空(无字符)。 When authority is present, the path must either be empty or begin with a slash ("/") character.
当存在权限时,路径必须为空或以斜杠(“/”)字符开头。 When authority is not present, the path cannot begin with two slash characters ("//").
当权限不存在时,路径不能以两个斜杠字符(“//”)开头。
A file:
URI can have an authority separator, //
, with an effectively empty authority after it, but it serves no purpose, so there is no harm in omitting it. 一个
file:
URI 可以有一个权限分隔符//
,后面有一个有效的空权限,但它没有用处,所以省略它没有任何害处。 It's still a fully compliant URI. 它仍然是完全兼容的URI。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.