Replacing single '\' with '\\' in Java

后端 未结 6 1608
离开以前
离开以前 2020-12-07 01:23

How do I replace a single \'\\\' with \'\\\\\'? When I run replaceAll() then I get this error message.

Exception in t         


        
6条回答
  •  孤城傲影
    2020-12-07 01:49

    filePath = filePath.replaceAll(Matcher.quoteReplacement("\"), Matcher.quoteReplacement("\\"));

    This one worked perfectly. filePath = C:\abc\

提交回复
热议问题