我有一个路径如下的 URI:
ftp://test:test@someftp/ready123/users/abc/#0#.
但是 URI 上的方法 getPath()
返回以下内容:
/ready123/users/abc/.
我需要像这样返回整个路径:
/ready123/users/abc/#0#
...这样我就可以将工作目录(CWD)更改为文件夹#0#。该代码采用通用方法,并且被许多其他应用程序使用。所以当我做出改变时我必须非常小心。我相信 # 之后的任何内容都被视为片段,但在本例中它实际上是文件夹的名称。
如何从 URI 对象获取路径 /ready123/users/abc/#0#
?
最佳答案
来自 URI 类的 JavaDoc:
URI syntax and components At the highest level a URI reference (hereinafter simply "URI") in string form has the syntax
[scheme:]scheme-specific-part[#fragment]
where square brackets [...] delineate optional components and the characters : and # stand for themselves.
因此,如果您想检索第一个 # 之后的所有内容,则需要使用 URI.getFragment()
关于java - URI.getPath() 在 '#' 之后不返回任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16300286/