项目在使用命令cmd窗口下 java -jar test.jar 的时候,报错task.properties (文件名、目录名或卷标语法不正确。
正常的war包是写法如下:
String path = PropertiesHander.class.getResource("/job_task.properties").getFile();
FileInputStream in = new FileInputStream(new File(path));
在项目打成jar包启动的时候报错无法运行,jar包方式的正确写法如下:
InputStream in = PropertiesHander.class.getClassLoader().getResourceAsStream("/job_task.properties") ;
本文解决在Java项目中,从jar包加载属性文件(job_task.properties)遇到的问题,对比了war包和jar包环境下加载属性文件的不同写法。
168万+

被折叠的 条评论
为什么被折叠?



