Reputation: 13706
Is there some nice way to safely manipulate file paths in Scala, transcending naive string manipulation?
I mean smart concatenation that adds missing slashes between path parts, Unix v.s. Windows slashes, automatically escaping spaces in paths, etc?
What would be a nice Java fallback for that?
Upvotes: 4
Views: 3789
Reputation: 167891
These days, better-files is one of the simplest and most widely used.
Previous answer: If you're willing to use an external library, rapture.io makes it about as easy as it can get.
Upvotes: 0
Reputation: 52681
You can do it this way:
import java.io.File
val a = "abc/def"
val b = "ghi/jk"
new File(a,b).getPath
// res0: String = abc/def/ghi/jk
Upvotes: 3