我想使用 ClassLoader 加载 Properties 类的属性文件。出于讨论的目的,我简化了以下代码以删除错误处理:
loader = this.getClass().getClassLoader();
in = loader.getResourceAsStream("theta.properties");
result = new Properties();
result.load(in);
在与此类相同的目录中,我有文件“theta.properties”,但 InputStream 始终为空。我是不是把文件放错地方了?我正在使用 eclipse 及其设置将类文件构建到源文件夹 - 所以这不应该是问题。
我在 JavaDoc 中找不到任何东西来让 ClassLoader 告诉我正在搜索什么类路径。