When to use “getResourceAsStream” method?

后端 未结 4 1295
死守一世寂寞
死守一世寂寞 2020-12-11 06:39

I was confused using the said method because while loading some properties file people are following a different approaches...

Properties prop 
 = new Proper         


        
4条回答
  •  臣服心动
    2020-12-11 06:51

    You can use the first approach if you are 100 % sure that the file location doesn't change across environments. This means there is a operations over head to make sure those directory paths are created across all environments. On the flip side, you have the flexibility of updating the properties file without opening the jar.

    The second approach is very portable as you are reading from the classpath. But it has the disadvantage of re-bundling the jar file for every property update.

    So, it basically depends upon your use-case.

提交回复
热议问题