How do I use the Java ClassLoader to load a file fromthe classpath?

前端 未结 3 2130
自闭症患者
自闭症患者 2020-12-31 18:34

I want to use the ClassLoader to load a properties file for the Properties class. I\'ve simplified the below code to remove error handling for the purposes of this discussio

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-31 19:13

    By using getClass().getClassloader() you look for "theta.properties" from the root path directory. Just use getClass().getResourceAsStream() to get a resource relative to that class.

提交回复
热议问题