getResourceAsStream() is returning null. Properties file is not loading

前端 未结 6 1282
眼角桃花
眼角桃花 2020-12-09 16:23

I am trying to load properties file. Here is my structure

\"Directory

Now i am trying to lo

6条回答
  •  爱一瞬间的悲伤
    2020-12-09 16:41

    I hope this helps !! You can keep your test.properties into src/main/resources

     public static Properties props = new Properties();
        InputStream inStream = Test.class.getResourceAsStream("/test.properties");
        try {
                loadConfigurations(inStream);
            } catch (IOException ex) {
                String errMsg = "Exception in loading configuration file. Please check if application.properties file is present in classpath.";
                ExceptionUtils.throwRuntimeException(errMsg, ex, LOGGER);
            }
        public static void loadConfigurations(InputStream inputStream) throws IOException{
                props.load(inputStream);
            }
    

提交回复
热议问题