简体   繁体   English

Java System.getProperty(“user.home”)

[英]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.

相关问题 Java System.getProperty(“ user.home”)目录缺少分隔符 - Java System.getProperty(“user.home”) directory missing separator Java:System.getProperty("user.home") 返回“?” - Java: System.getProperty("user.home") returns "?" Java System.getProperty(“ user.home”)如何返回其他用户(pi)的主页? - Java System.getProperty(“user.home”) how return home for other user (pi)? System.getProperty(“user.home”) 的 Inno Setup 常量等效项 - Inno Setup constant equivalent for System.getProperty(“user.home”) 通过 System.getProperty("user.home") 使用字符串作为文件位置参考 - Using Strings for File Location Reference with System.getProperty("user.home") 我如何使用根目录System.getProperty(“ user.home”) - how can i use the root directory System.getProperty(“user.home”) Tomcat上的System.getProperty(“ user.home”)返回“ / usr / share / tomcat7 /” - System.getProperty(“user.home”) on Tomcat returns “/usr/share/tomcat7/” 在Tomcat上运行时,System.getProperty(“ user.home”)返回/ root - System.getProperty(“user.home”) returns /root when running on Tomcat System.getProperty(“ java.home”)的问题 - Problems with System.getProperty(“java.home”) System.getProperty(“ gradle.user.home”)返回null - System.getProperty(“gradle.user.home”) returns null
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM