Groovy:用替换/in路径\

Groovy:用替换/in路径\,groovy,escaping,backslash,slash,Groovy,Escaping,Backslash,Slash,在Groovy中如何将/替换为\?以便 “//10.1.1.1/temp/test”变为“\\10.1.1\temp\test” “//10.1.1.1/temp/test.replaceAll(//'\\//','\\')看看这个“//10.1.1.1/temp/test.replaceAll(“/”,“\\\\”)“\\\”生成一个反斜杠 请检查这个 最后你会得到这样的结果 注意迭代器中的toString方法。。。f=new File('c:/temp/test/')f.eachFileMa

在Groovy中如何将
/
替换为
\
?以便
“//10.1.1.1/temp/test”
变为
“\\10.1.1\temp\test”

“//10.1.1.1/temp/test.replaceAll(//'\\//','\\')
看看这个
“//10.1.1.1/temp/test.replaceAll(“/”,“\\\\”)
<代码>“\\\”生成一个反斜杠

请检查这个

最后你会得到这样的结果


注意迭代器中的toString方法。。。f=new File('c:/temp/test/')f.eachFileMatch{it.split(\\\”[1]。length()==3}{println it.toString().replaceAll(\\\\”,“/”)无效:java.lang.IllegalArgumentException:缺少要转义的字符
 String path = 'D:/folder1/folder2/yourfile' 
 String result = path.replaceAll( "/","\\");
'D:\folder1\folder2\yourfile'