两种方式
String path = "excel/constant.xlsx" ;
// 直接获取文件
1 File file1 = new DefaultResourceLoader().getResource(path).getFile();
// 获取路径
2 String file = Thread.currentThread().getContextClassLoader().getResource(path).getFile();
InputStream in = new FileInputStream(file);
文件位置
获取的是编译后路径
3 其他方式
ConstantChangeController.class.getResource("").getPath(); // 类当前路径
/D:/Projects/ipaas/iuap-ipaas-dataintegration-develop/gwportal/target/classes/com/yonyou/nccloud/gwp/integrated/
ConstantChangeController.class.getResource("/").getPath(); // resource 下路径
/D:/Projects/ipaas/iuap-ipaas-dataintegration-develop/gatewayweb-starter/target/classes/
ConstantChangeController.class.getClassLoader().getResource("").getPath(); // resource 下路径
/D:/Projects/ipaas/iuap-ipaas-dataintegration-develop/gatewayweb-starter/target/classes/
ConstantChangeController.class.getClassLoader().getResource("/").getPath(); // 无法获取
4 直接获取 InputStream
InputStream resourceAsStream = ConstantChangeController.class.getResourceAsStream(path);