If you happen to be using Spring already, I have found the org.springframework.web.util.UriComponentsBuilder to be quite nifty. Here is how you would use it in your case.
final URL myUrl = UriComponentsBuilder
.fromHttpUrl("http://IP:4567/foldername/1234?abc=xyz")
.build()
.toUri()
.toURL();