获取我们自己项目中类路径下的文件

时间:2014-05-01 21:53:04   收藏:0   阅读:356

例如我们要获取我们项目类路径下的image-manager.properties 

mamicode.com,码迷



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;
}

获取我们自己项目中类路径下的文件,码迷,mamicode.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!