[英]Java System.getProperty(“user.home”)
In this line of code, I am using the getProperty
method:在这行代码中,我使用了
getProperty
方法:
PrintWriter writer = new PrintWriter("~/4413/ctrl/geo.txt".replaceFirst("^~", System.getProperty("user.home")), "UTF-8");
The result is C:UsersKamel\4413\ctrl\geo.txt
which not exactly what I want as long as some \
separators are missing at the begining.结果是
C:UsersKamel\4413\ctrl\geo.txt
缺少一些\
分隔符,这不完全是我想要的。
Is there anything I can add so that the path becomes correct?我可以添加什么以使路径正确吗?
Quote System.getProperty("user.home")
:引用
System.getProperty("user.home")
:
Matcher.quoteReplacement(System.getProperty("user.home"))
The issue is that both parameters of replaceFirst
treat characters in special ways, because you are dealing with regular expressions, not literal strings.问题是
replaceFirst
的两个参数都以特殊方式处理字符,因为您处理的是正则表达式,而不是文字字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.