Given this Path
object in Java:
Path path = Path.of("foo", "bar");
I would like to convert it into a String, always using the UNIX path separator, even on Windows.
When I convert it into a String (using path.toString()
), if I am running on Windows, I get "foo\bar"
.
How can I reliably get "foo/bar"
?
Are there any other solutions except a) stop using a Path
altogether, or b) adding .replace("\", "/)
, which would introduce a platform-specific fix?