java URL using relative path

I have a URL:

URL url=new URL("");

and a relative path:

String relativePath="../file2.html"; //maybe is "/file3.html"

I want to get using variable url and relativePath

How to do it? This is very frequent requirement you see if you are dealing with webservices development. One of the best answer i came across for this is:

new URL(url, relativePath);

toString() returns the string representation of the given URL object. For this case, toString() prints the url as

Leave a Reply

Your email address will not be published. Required fields are marked *