fix: 导入用户自定义配置文件
This commit is contained in:
parent
a391ed05e0
commit
877976f1d7
@ -21,9 +21,22 @@ import java.util.Objects;
|
|||||||
public class ShortcutKey implements ShortcutKeyInterface {
|
public class ShortcutKey implements ShortcutKeyInterface {
|
||||||
@Override
|
@Override
|
||||||
public void createShortcutKeyByConfig() {
|
public void createShortcutKeyByConfig() {
|
||||||
|
String rootPath =System.getProperty("user.dir");
|
||||||
|
// 构建JSON文件路径
|
||||||
|
String jsonFilePath = rootPath +"/config/shortcutKey.json";
|
||||||
InputStream inputStream = getClass().getResourceAsStream("/config/shortcutKey.json");
|
InputStream inputStream = getClass().getResourceAsStream("/config/shortcutKey.json");
|
||||||
StringBuffer jsonData = new StringBuffer();
|
StringBuffer jsonData = new StringBuffer();
|
||||||
|
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))) {
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
|
||||||
String line;
|
String line;
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
@ -32,6 +45,8 @@ public class ShortcutKey implements ShortcutKeyInterface {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 转json对象
|
// 转json对象
|
||||||
GsonBuilder gsonBuilder = new GsonBuilder();
|
GsonBuilder gsonBuilder = new GsonBuilder();
|
||||||
Gson gson = gsonBuilder.create();
|
Gson gson = gsonBuilder.create();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user