How to escape “\” characters in Java

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

    The really system-independent way is to do this:

    String aa = "E:/dev_workspace1/AccessCore/WebRoot/DataFile";
    String output = aa.replace('/', File.separatorChar);
    

    It will give you "E:\dev_workspace1\AccessCore\WebRoot\DataFile" on Windows and "E:/dev_workspace1/AccessCore/WebRoot/DataFile" just about everywhere else.

提交回复
热议问题