将相对URL附加到java.net.URL [英] Append relative URL to java.net.URL
问题描述
如果我有一个java.net.URL对象,指向让我们说
Provided I have a java.net.URL object, pointing to let's say
http://example.com/myItems
或 http://example.com/myItems/
在某处有一些助手吗?在这附加一些相对的URL?
例如附加 ./ myItemId
或 myItemId
获取:
http://example.com/myItems/myItemId
Is there some helper somewhere to append some relative URL to this?
For instance append ./myItemId
or myItemId
to get :
http://example.com/myItems/myItemId
推荐答案
URL
有一个构造函数,它带有一个基本 URL
和一个 String
规范。
URL
has a constructor that takes a base URL
and a String
spec.
或者, java.net.URI
更贴近标准,并且resolve
方法做同样的事情。使用 URL 创建 URI
6 / docs / api / java / net / URL.html #toURI%28%29> URL.toURI
。
Alternatively, java.net.URI
adheres more closely to the standards, and has a resolve
method to do the same thing. Create a URI
from your URL
using URL.toURI
.
这篇关于将相对URL附加到java.net.URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!