Instead of java.net.URL use URI
val uri = URI.create(yamlUrl) //Then you can just use .toURL() to get the url val connection = uri.toURL().openConnection()