该方法System.getProperty("user.dir")
返回如下内容:
C:\Users\myuser\path
但是在我的程序中,我需要使用双斜杠,如下所示:
C:\\\Users\\\myuser\\\path
有没有简单的方法来添加这些双斜杠?
使用string.replace
功能。
System.out.println("C:\\Users\\myuser\\path".replace("\\", "\\\\"));
IE,
System.out.println(System.getProperty("user.dir").replace("\\", "\\\\"));
更新:
String s = "C:\\Users\\myuser\\path";
System.out.println(s.replace("\\", "\\\\\\"));
输出:
C:\\\Users\\\myuser\\\path
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句