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;
    }
}

posted on 2024-07-11 22:09  荷楠仁  阅读(2)  评论(0编辑  收藏  举报

导航