How to escape “\” characters in Java

后端 未结 5 441
说谎
说谎 2020-12-11 06:31

As we all know,we can use

string aa=@\"E:\\dev_workspace1\\AccessCore\\WebRoot\\DataFile\" 

in c# in order not to double the \'\\\'.

5条回答
  •  醉梦人生
    2020-12-11 07:14

    If you write a path, you should use the '/' as path-separator under Java. The '/' is the official path-separator under Java and will be converted to the appropriate separator for the platform (\ under windows, / under unix). The rest of the string is unchanged if passed to the system, so the '\' also works under windows. But the correct way to represent this path is "E:/dev_workspace1/AccessCore/WebRoot/DataFile".

    If you want to represent a '\' in a Java-String you have to escape it with another one: "This String contains a \".

提交回复
热议问题