-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoadConfig.java
More file actions
34 lines (27 loc) · 879 Bytes
/
Copy pathLoadConfig.java
File metadata and controls
34 lines (27 loc) · 879 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package modular;
import data.Config;
import javax.swing.*;
import java.io.File;
import java.io.FileInputStream;
import java.nio.file.Files;
import java.util.Properties;
public class LoadConfig {
public synchronized static void loadConfig() {
try {
Properties config;
File file = new File("config.properties");
if (!file.exists()) {
// 检查是否存在配置文件,如果不存在则是第一次打开游戏
Config.ifFirstGame = true;
SaveConfig.saveConfig();
return;
}
config = new Properties();
config.load(Files.newInputStream(file.toPath()));
Config.initConfig(config);
} catch (Exception e) {
e.printStackTrace();
JOptionPane.showMessageDialog(new JFrame(), "读取配置文件失败");
}
}
}