我尝试读取一个 .properties 文件并得到如下代码:
public final class Config {
static {
Properties properties = new Properties();
InputStream propertiesStream = Object.class.getResourceAsStream("config.properties");
if (propertiesStream != null) {
try {
properties.load(propertiesStream);
} catch (IOException e) {
e.printStackTrace();
}
} else {
System.out.println("file not found");
}
}
}
但是一直提示找不到文件。
属性的内容是
pwd=passw0rd
有人知道怎么解决这个问题吗?
最佳答案
应该在classpath下,放到你的根源码包里,如果是maven项目就放到src/main/resources
目录下
关于java - 在哪里放置属性文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16806434/