您的位置:首页 > 编程语言 > Java开发

java读取配置文件(使用java.util.Properties读取)

2017-11-03 14:14 716 查看
读取resource下的test.properties文件,代码如下

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class PropertiesUtil {

public String getValue(String name){
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("test.properties");
Properties properties = new Properties();
try{
properties.load(inputStream);
}catch (IOException ioE){
ioE.printStackTrace();
}finally{
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
System.out.println(name+":"+properties.getProperty(name));
return properties.getProperty(name);
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: