java Paths double forward slash

Viewed 462
import java.nio.file.Paths
Paths.get("viewfs://x", "b", "c").toString

gives viewfs:/x/b/c but I want viewfs://x/b/c Not sure what I am missing?

1 Answers

To have a properly formatted Uniform Resource Identifier URI for identification of a particular resource, use java.net.URI with scheme, host, and relative path.

import java.net.URI

val scheme = "viewfs"
val host = "x"
val path = Paths.get("/", "b", "c").toString //Path starts with "/" to handle exception - java.net.URISyntaxException: Relative path in absolute URI

val uri = new URI(scheme, host, path, null)
println(uri.toString) 

//Output - viewfs://x/b/c
Related