Java URL toURI() 方法

2025年3月24日 | 1 分钟阅读

toURI() 方法返回与给定 URL 等效的 URI。此方法的功能与 new URI (this.toString()) 相同。

语法

返回值

URI 实例等同于此 URL。

Throw

URISyntaxException - 如果此 URL 的格式严格不符合 RFC2396 并且无法转换为 URI。

自从 (Since)

1.5

示例 1

输出

URL created: https://tpointtech.cn/URL-class
URI from URL: https://tpointtech.cn/URL-class

示例 2

输出

URL:file:/D:/Advancejava/UrlClass/file%20name%20with%20spaces.txt
URI:file:/D:/Advancejava/UrlClass/file%20name%20with%20spaces.txt
URL (no special character handling):file:/D:/Advancejava/UrlClass/file name with spaces.txt
下一个主题Java URL 类