Java单例模式
public enum ConfReader {
INSTANCE;
private Conf conf;
ConfReader() {
InputStream is = null;
try {
File initialFile = new File("conf.yml");
is = new FileInputStream(initialFile);
Yaml yaml = new Yaml();
this.conf = yaml.loadAs(is, Conf.class);
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
} finally {
try {
is.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
public Conf getConf() {
return this.conf;
}
}