fix: 导入用户自定义配置文件

This commit is contained in:
kb 2023-08-20 01:22:37 +08:00
parent a391ed05e0
commit 877976f1d7

View File

@ -21,17 +21,32 @@ import java.util.Objects;
public class ShortcutKey implements ShortcutKeyInterface {
@Override
public void createShortcutKeyByConfig() {
String rootPath =System.getProperty("user.dir");
// 构建JSON文件路径
String jsonFilePath = rootPath +"/config/shortcutKey.json";
InputStream inputStream = getClass().getResourceAsStream("/config/shortcutKey.json");
StringBuffer jsonData = new StringBuffer();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
String line;
while ((line = reader.readLine()) != null) {
jsonData.append(line);
File file = new File(jsonFilePath);
if(file.exists()){
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
String line;
while ((line = reader.readLine()) != null) {
jsonData.append(line);
}
} catch (IOException e) {
e.printStackTrace();
}
}else {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
String line;
while ((line = reader.readLine()) != null) {
jsonData.append(line);
}
} catch (IOException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
// 转json对象
GsonBuilder gsonBuilder = new GsonBuilder();
Gson gson = gsonBuilder.create();