简体   繁体   English

URI.getPath()在“#”之后不返回任何内容

[英]URI.getPath() does not return anything after '#'

I have a URI with path like this : 我有一个带有这样的路径的URI:

ftp://test:test@someftp/ready123/users/abc/#0#.

But the method getPath() on the URI returns this: 但是URI上的方法getPath()返回以下内容:

/ready123/users/abc/. 

I need the whole path to be returned like this : 我需要像这样返回整个路径:

/ready123/users/abc/#0#

... So that I can change the working directory(CWD) to the folder #0#. ...这样我就可以将工作目录(CWD)更改为文件夹#0#。 The code is in a generic method and is jarred up which gets used by many other applications. 该代码采用通用方法,因此被许多其他应用程序所使用。 So I have to be very careful when I make changes. 因此,在进行更改时必须非常小心。 I believe anything after # is considered as a fragment, but in this case it is actually the name of a folder. 我相信#之后的所有内容都被视为片段,但在这种情况下,它实际上是文件夹的名称。

How do I get the path /ready123/users/abc/#0# from the URI object ? 如何从URI对象获取路径/ready123/users/abc/#0#

From the JavaDoc of URI class: 从URI类的JavaDoc中:

URI syntax and components At the highest level a URI reference (hereinafter simply "URI") in string form has the syntax URI语法和组件在最高级别,字符串形式的URI参考(以下简称为“ URI”)具有以下语法

 [scheme:]scheme-specific-part[#fragment] 

where square brackets [...] delineate optional components and the characters : and # stand for themselves. daccess-ods.un.org daccess-ods.un.org方括号中描述了可选组件,字符:和#代表自己。

As such if you want to retrieve everything after the first # you need to use URI.getFragment() 这样,如果要检索第一个#之后的所有内容,则需要使用URI.getFragment()

You need to replace the hash character with %23 您需要将哈希字符替换为%23

 URI uir = new URI("ftp://test:test@someftp/ready123/users/abc/%230%23");
 System.out.println(uir.getPath()); // returns '/ready123/users/abc/#0#'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM