修复加载配置文件异常的情况,catch后返回空字符串

This commit is contained in:
yutou 2020-12-24 16:47:14 +08:00
parent ce7440f5b1
commit 86287dacf6

View File

@ -32,12 +32,16 @@ public class ConfigTools {
//System.out.println(type+"配置文件地址:"+file.getAbsolutePath());
String src=readFile(file);
if(src!=null){
JSONObject json=JSONObject.parseObject(src);
if(json==null){
json=new JSONObject();
saveFile(file,json.toJSONString());
try {
JSONObject json=JSONObject.parseObject(src);
if(json==null){
json=new JSONObject();
saveFile(file,json.toJSONString());
}
return json.getOrDefault(key, "");
}catch (Exception e){
return "";
}
return json.getOrDefault(key, "");
}
return "";
}