Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (9.5k points)

Below is the construct I’ve which I use in Oracle Java 1.8.0_25: 

URL url = new URL(new URL(new URL("http://localhost:4567/"), "123"), "asd")

According to the documentation here, it should give me the URL ‘http://localhost:4567/123/asd’. Instead, I get the following URL ‘http://localhost:4567/asd’. Can anyone tell me how to go about this?

1 Answer

0 votes
by (19.7k points)

With the constructor ‘URL(URL baseURL, String relativeURL)’, you can do the below things: 

URL baseUrl = new URL("http://localhost:4567/");

URL url = new URL(baseUrl, "123/asd")

The output will be: http://localhost:4567/123/asd

Interested in Java? Check out this Java tutorial by Intellipaat.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...