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

前端 未结 3 2119
自闭症患者
自闭症患者 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条回答
  •  旧时难觅i
    2020-12-31 18:48

    If the file is in the same directory as the class, you have to prefix the class's package as a directory.

    So if your package is:

    package com.foo.bar;
    

    Then your code is:

    .getResourceAsStream("com/foo/bar/theta.properties");
    

提交回复
热议问题