java 读取配置文件

public class ApplicationProperty {
    private final Properties prop = new Properties();
    private static ApplicationProperty instance = null;
    private ApplicationProperty(){}
    public static synchronized ApplicationProperty getInstance(){
        if (instance == null){
            instance = new ApplicationProperty();
            return instance;
        } else {
            return instance;
        }
    }
    public Properties getProperty(){
        try {
            InputStream in = this.getClass().getClassLoader().getResourceAsStream("application.properties");
//            System.out.println(in.toString());
            this.prop.load(in);
            in.close();
        } catch (Exception e){
            e.printStackTrace();
        }
        return this.prop;

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.