例如我们要获取我们项目类路径下的image-manager.properties
java代码如下
import org.apache.tools.ant.taskdefs.LoadProperties;
protected String readConfig() throws FileNotFoundException, IOException {
InputStream in = LoadProperties.class.getClassLoader()
.getResourceAsStream("image-manager.properties");
Properties properties = new Properties();
properties.load(in);
String sourcePath = properties.getProperty("root"); //properites文件中的键的名字。 返回的是该键对应得分值!
return sourcePath;
}