Home » Java » java – Paths.get("/xyz") returns \xyz instead of /xyz-Exceptionshub

java – Paths.get("/xyz") returns \xyz instead of /xyz-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

I am trying to create a virtual file system using Apache MINA virtual file system. While creating new file system for a specific user using own customized provider, i need to set the root of the file system which will act as a key to get the file system in further processes.
So in order to set the root directory i do Paths.get("schema://" +userName). which is not working as expected as i explained below.

Seeking a value of /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: