您好,欢迎访问一九零五行业门户网

如何在Java的.properties文件中写入反斜线\?

问题我的是ssh项目,需要做一个文件上传,然后文件路径需要读取properties配置
在resource下有config/application.properties
然后工具类是这样写的,这个是可以用的
import java.io.ioexception;import java.io.inputstream;import java.util.enumeration;import java.util.missingresourceexception;import java.util.properties;import java.util.resourcebundle;public class propertiesutil { private static properties props = new properties(); private static propertiesutil instances = null; private static string name = "config//application"; public static propertiesutil getinstance() { if (null == instances) { instances = new propertiesutil(); } return instances; } private propertiesutil() { init(name); public synchronized void init(string spropfilepathname) throws missingresourceexception { string propfile = spropfilepathname; resourcebundle bundle = resourcebundle.getbundle(propfile); enumeration enume = bundle.getkeys(); object key = null; object value = null; while (enume.hasmoreelements()) { key = enume.nextelement(); value = bundle.getstring(key.tostring()); props.put(key, value); public string getproperty(string key) { return props.getproperty(key); public static string getvalue(string filepath, string key) { inputstream in = null; string value = null; try { in = propertiesutil.class.getresourceasstream(filepath); props.load(in); value = props.getproperty(key); } catch (exception e) e.printstacktrace(); }finally{ try { if(in != null) { in.close(); } } catch (ioexception e) e.printstacktrace(); return value; } public static void main(string[] args) { system.out.println(propertiesutil.getinstance().getproperty("属性key"));}
如果我在properties写成如下
项目直接启动不起来,报了error
解决经过研究,properties使用“\”相当于是java的转义符
如果想要写出\的效果,只需修改如下写法即可
然后项目起来了,然后看数据库插入的path也正常~
以上就是如何在java的.properties文件中写入反斜线\?的详细内容。
其它类似信息

推荐信息