What is the difference between getResourceAsStream with and without getClassLoader?

前端 未结 3 1820
迷失自我
迷失自我 2021-02-19 19:50

I\'d like to know the difference between the following two:

MyClass.class.getClassLoader().getResourceAsStream(\"path/to/my/properties\");

and

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-19 19:58

    The main practical difference is that you can use relative paths when you go through the class. So if your properties are in the same package as MyClass, you can do

    MyClass.class.getResourceAsStream("properties");
    

提交回复
热议问题