Java文件操作property文件

来源:互联网 发布:elasticsearch python 编辑:程序博客网 时间:2024/05/29 15:47

有时候,需要直接在java文件中访问.property配置文件。

代码如下。

Properties prop = new Properties();InputStream inputFile = null;try {inputFile = 当前类名.class.getResourceAsStream("/ufinterface.properties");prop.load(inputFile);} catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();} finally {try {inputFile.close();} catch (IOException e) {e.printStackTrace();}}
还有,这个.properyt在,src/main/resources下面。

0 0
原创粉丝点击