How to escape forward slash in java so that to use it in path

后端 未结 5 2189
生来不讨喜
生来不讨喜 2020-12-19 14:53

I am trying to escape forward slash in String which can be used in path using Java.
For example: String:: \"Test/World\"
Now I want to use above string

5条回答
  •  感动是毒
    2020-12-19 15:05

    We are trying to solve exactly the same problem (using filesystem path as node name in zookeeper) a we haven't found a way how to have '/' in node name.

    Solution would be either to replace '/' with some character, that cannot appear in your node name. For paths that would be '/' or '\0', which wont help us in this case.

    Other possibility is to replace '/' with string of characters allowed in node name, e.g. "Test/World" -> "Test%@World", "Test%World" -> "Test%%World" and add escaping/de-escaping to saving and loading.

    If there is any more straightforward way, I'd love to hear it.

提交回复
热议问题