java读取properties文件的方法实例分析


本文实例讲述了java读取properties文件的方法。分享给大家供大家参考。具体分析如下:

1.不在项目中读取:

Properties properties = new Properties();
BufferedReader read = new BufferedReader(new InputStreamReader(new FileInputStream("文件的路径"),"utf-8"));
properties.load(read);
properties .getProperty("那个文件的key")

2.在项目中读取:

InputStream inputStream =你那工具类的类名.class.getResourceAsStream("/文件名.properties");
Properties p = new Properties();
try {
p.load(inputStream);
inputStream.close();
} catch (IOException e1) {
e1.printStackTrace();
}

都是通过p.getProperty(配置文件里的key)获得value的

希望本文所述对大家的java程序设计有所帮助。


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3