how to get URL using relative path

前端 未结 6 751
醉话见心
醉话见心 2020-12-15 16:33

I have a URL:

URL url=new URL(\"http://www.abc.com/aa/bb/cc/file.html\");

and a relative path:

String relativePath=\"../fil         


        
6条回答
  •  半阙折子戏
    2020-12-15 17:04

    Try operating winth the class URI instead of the URL.

    To get the URI from your URL:

    java.net.URI anURI=url.toUri();
    

    Then, to resolve the relative URI:

    URI resultURI=anURI.resolve(relativePath);
    

    And at last, to get an URL type use de method toUrl() of the URI result variable, and you've got it.

提交回复
热议问题