When to use “getResourceAsStream” method?

后端 未结 4 1298
死守一世寂寞
死守一世寂寞 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条回答
  •  旧时难觅i
    2020-12-11 07:01

    When reading a file from the filesystem use a FileInputStream(File()) using relative or absolute paths.

    when your program is distributed as a jar and you need to load a file that is inside that jar, you need to use getResourceAsStream(), it will search the classpath for the file, and the path is relative to the classpath.

提交回复
热议问题