When to use “getResourceAsStream” method?

后端 未结 4 1281
死守一世寂寞
死守一世寂寞 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:58

    getResourceAsStream searchs you classpath for the given file/resource and it can also provide InputStreams of resources from inside a JAR.

    So, if your properties exist in some folder in the physical filesystem (e.g. user folder, ...) use FileInputStream and if the file is embedded in your classpath (e.g. as a resource inside the JAR) use getResourceAsStream.

提交回复
热议问题