commit
45d9f4b4fc
@ -9,7 +9,8 @@ import org.jcnc.jnotepad.Interface.ShortcutKeyInterface;
|
|||||||
import org.jcnc.jnotepad.tool.FileUtil;
|
import org.jcnc.jnotepad.tool.FileUtil;
|
||||||
import org.jcnc.jnotepad.view.manager.ViewManager;
|
import org.jcnc.jnotepad.view.manager.ViewManager;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.*;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@ -20,14 +21,36 @@ import java.util.Objects;
|
|||||||
public class ShortcutKey implements ShortcutKeyInterface {
|
public class ShortcutKey implements ShortcutKeyInterface {
|
||||||
@Override
|
@Override
|
||||||
public void createShortcutKeyByConfig() {
|
public void createShortcutKeyByConfig() {
|
||||||
String json = "src/main/resources/config/shortcutKey.json";
|
String rootPath =System.getProperty("user.dir");
|
||||||
File jsonFile = new File(json);
|
// 构建JSON文件路径
|
||||||
// 读取json文件
|
String jsonFilePath = rootPath +"/config/shortcutKey.json";
|
||||||
String jsonData = FileUtil.getJsonStr(jsonFile);
|
InputStream inputStream = getClass().getResourceAsStream("/config/shortcutKey.json");
|
||||||
|
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))) {
|
||||||
|
String line;
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
jsonData.append(line);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 转json对象
|
// 转json对象
|
||||||
GsonBuilder gsonBuilder = new GsonBuilder();
|
GsonBuilder gsonBuilder = new GsonBuilder();
|
||||||
Gson gson = gsonBuilder.create();
|
Gson gson = gsonBuilder.create();
|
||||||
Map<String, String> shortcutKeyConfig = gson.fromJson(jsonData, new TypeToken<Map<String, String>>() {
|
Map<String, String> shortcutKeyConfig = gson.fromJson(jsonData.toString(), new TypeToken<Map<String, String>>() {
|
||||||
}.getType());
|
}.getType());
|
||||||
for (Map.Entry<String, String> stringObjectEntry : shortcutKeyConfig.entrySet()) {
|
for (Map.Entry<String, String> stringObjectEntry : shortcutKeyConfig.entrySet()) {
|
||||||
// 保证json的key必须和变量名一致
|
// 保证json的key必须和变量名一致
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user