在windows环境下,加载外部文件作为配置,出现没思路或者文件路径不存在的问题
一 、区分相对路径和绝对路径
不以 / 开头,被视为相对路径 此时要注意工作目录
比如src/main/resources/config-external.json是相对路径
它的绝对路径就是工作目录拼接上相对路径
D:\center\gtms-switch-center\src/main/resources/config-external.json
二 给json文件的绝对路径放在application.properties里,起个键名nb.config,用CommonUtil.getProperties("nb.config")读出来
String jsonFilePath = CommonUtil.getProperties("xxx.jsonFile.path");File jsonFile = new File(jsonFilePath);#判断路径是否存在
File jsonFile = new File(jsonFilePath);Path path1 = Paths.get(js