How to escape “\” characters in Java

后端 未结 5 453
说谎
说谎 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:23

    There is no whole string escape operator but, if it's for file access, you can use a forward slash:

    String aa="E:/dev_workspace1/AccessCore/WebRoot/DataFile";
    

    Windows allows both forward and backward slashes as a path separator. It won't work if you pass the path to an external program that mangles with it and fails, but that's pretty rare.

提交回复
热议问题