Java读取maven目录下的*.properties配置文件

public class ReadProperties{
    
    private static String proFileName = "/config/MQSubjectId.properties"; 
    private static Properties pro;  
     
    static{  
        try {             
            pro = new Properties();  
            InputStream in = ClassLoader.class.getResourceAsStream(proFileName);  
            pro.load(in);  
            in.close();  
        } catch (IOException e) {  
            e.printStackTrace();  
        }  
    } 
}
import java.util.Properties;

public class SystemVar {
    private static Properties cache = new Properties();

    static {
        try {
            cache.load(ClassLoader.class.getResourceAsStream("/config/systemConfig.properties"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static String getValue(String key){
        return cache.getProperty(key);
    }
    public static void main(String[] args) {
        System.out.println(getValue("environment"));
    }
}

 

posted @ 2018-03-23 09:48  如果屈原会编程  阅读(436)  评论(0编辑  收藏  举报