获取我们自己项目中类路径下的文件
时间:2014-05-01 21:53:04
收藏:0
阅读:356
例如我们要获取我们项目类路径下的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;
}
评论(0)