Home » Java » java – Paths.get("/xyz") returns '\xyz', but I want it to return '/xyz'-Exceptionshub

java – Paths.get("/xyz") returns '\xyz', but I want it to return '/xyz'-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

I am trying to get '/xyz' from Paths.get("/xyz") but it returns '\xyz'.
The above requirement is to save the File System with the key as path value. When i try to save the file system using Paths.get() as key mentioned above it saves with a \ instead of / and becomes difficult while retrieving it with actual value.
Below are the versions which i have tried

Paths.get("/xyz")
Paths.get(File.pathSeparator+ "xyz")
Paths.get(File.separator+"xyz")

they return

\xyz
;xyz
\xyz

Any way if i could achieve this?

How to&Answers: