.properties-file 中的特殊字符(“\") [英] Special characters ("\") in .properties-file
问题描述
我正在开发一个在 Windows 上执行的 Java 应用程序.我在 .properties 文件中有几个反斜杠(\").这是文件的样子:
I'm developing a Java application that executes on Windows. I have several backslashes ("\") in a .properties-file. This is what the file looks like:
dir=\\127.0.0.1\d$\dir\dir2\dir3
我使用Spring
注解Value
来读取属性dir
:
I read the property dir
using Spring
annotation Value
:
@Value("${dir}")
protected String dir;
当在代码中使用属性 dir
时,这会产生字符串 127.0.0.1d$dirdir2dir3
.
This results in the string 127.0.0.1d$dirdir2dir3
when the property dir
is used in the code.
我尝试过这样的 unicode 转义:
I have tried unicode escapes like this:
dir=\u005C\u005C127.0.0.1\u005Cd$\u005Cdir\u005Cdir2\u005Cdir3
我也试过反斜杠这样的转义:
I have also tried backslash as escape like this:
dir=\\\\127.0.0.1\\d$\\dir\\dir2\\dir3
当在代码中使用属性 dir
时,上述两种尝试都会产生字符串 \\127.0.0.1d$dirdir2dir3
.
Both of the tries above results in the string \\127.0.0.1d$dirdir2dir3
when the property dir
is used in the code.
我希望在代码中使用属性 dir
时将属性设置为 \\127.0.0.1\d$\dir\dir2\dir3
..properties-file 应该是什么样子才能得到这个结果?
I want the property dir
to be set to \\127.0.0.1\d$\dir\dir2\dir3
when the property is used in the code. What shall the .properties-file look like to get this result?
推荐答案
您可以使用正斜杠,因为它适用于 Windows 的原因
You can use forward slashes, beyond reason it works on Windows
这篇关于.properties-file 中的特殊字符(“\")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!