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

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