Java 在属性文件中转义特殊字符

Java 在属性文件中转义特殊字符,java,velocity,Java,Velocity,在Velocity属性文件中,如何转义逗号和空格等特殊字符 问题是它读取的模板在 文件夹1:模板1 但不在文件夹2内:逗号,模板2 文件comma_template.vm位于文件夹comma,templates2内 错误: Exception in thread "main" org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'comma_template.vm' “速度”

在Velocity属性文件中,如何转义逗号和空格等特殊字符

问题是它读取的模板在

文件夹1:模板1 但不在文件夹2内:逗号,模板2

文件comma_template.vm位于文件夹comma,templates2内

错误:

    Exception in thread "main" org.apache.velocity.exception.ResourceNotFoundException:
 Unable to find resource 'comma_template.vm'

“速度”将在处分割路径,。它无法识别您的文件夹名称中包含逗号,因此它会看到三条路径:

 C:/Users/Joseph.M/WorkPlace_Struts2/Velocity-ECnet/templates1
 C:/Users/Joseph.M/WorkPlace_Struts2/Velocity-ECnet/comma
 templates2
要解决这个问题,必须重命名文件夹-避免使用空格和逗号

另一种解决方案可能是使用URLResourceLoader。然后可以对非法字符进行编码:

"file:///C:/Users/Joseph.M/WorkPlace_Struts2/Velocity-ECnet/templates1, "+
    "file:///C:/Users/Joseph.M/WorkPlace_Struts2/Velocity-ECnet/comma%2c%20templates2"

请编辑您的问题,并确保所有名称与template1匹配,有时会有一个s。另外:您想查看Velocity文件夹的逗号、模板还是文件夹的逗号和模板,还有一个2缺失。感谢您的回复。很抱歉输入错误,请查找更新的问题。
"file:///C:/Users/Joseph.M/WorkPlace_Struts2/Velocity-ECnet/templates1, "+
    "file:///C:/Users/Joseph.M/WorkPlace_Struts2/Velocity-ECnet/comma%2c%20templates2"