I have a URL:
URL url=new URL("https://example.com/aa/bb/cc/file.html");
and a relative path:
String relativePath="../file2.html"; //maybe is "/file3.html"
I want to get http://example.com/aa/bb/file2.html
using variable url
and relativePath
How to do it?
new URL(url, relativePath);
如果要构建指向相关文件的 URL,可以使用:
URL url = new URL(new URL("file:"), "./myLocalFile.txt");
When building relative URL, keep in mind that the base is path to current package, not file. I mean: the referer file is in .../myProject/src/pckg/javafile.java
and the referated file is in .../myProject/some-other/nice.file
, then the relative reference should look like this:
URL url = new URL(new URL("file:"), "./../some-other/nice.file");
and this works for me as well:
URL url = new URL("file:./../some-other/nice.file");
我发现有效的是:
new URL("file:./src/gui/Something.fxml")
这适用于我的代码URL url=Myclass.class.getResource("/com/fnf/si/DepAcctInq_V02.wsdl");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.