我的项目中含有properties文件,但是导出来的jar运行报错,
说是读取配置文件的属性值没有拿到,程序没有问题的。
properties配置文件读取路径不对吧,
Properties pro = new Properties();
String path = Thread.currentThread().getContextClassLoader().getResource("").toString();
path = path.replace('/', '\');
path = path.replace("file:", "");
获取到class文件所在的根目录,根据这个目录下读取你properties配置文件试试
没问题了 ,我中间使用的是fileinputstream 只能传入绝对路径,相对路径不行 ,后来改成getResource("")的方式,写绝对路径就可以了。