Properyies文件的读取

本文介绍了一种使用Java的Properties类从文件中读取配置信息的方法,并将其存储为Map数据结构以便于后续使用。

当我们使用Properyies存储数据的时候是以键值对形式的,可以存储到Map数据中,我们就可以用前面的key值来获取后面的value

public Map<String,String> getProperyies(){
        Properties properties = new Properties();
        Map<String, String> stringStringHashMap = new HashMap<>();
        InputStream resourceAsStream = getClass().getResourceAsStream("type.peoperyies");
        try {
            properties.load(resourceAsStream);
            Enumeration<?> enumeration = properties.propertyNames();
            while(enumeration.hasMoreElements()){
                String o = (String) enumeration.nextElement();
                String property = properties.getProperty(o);
                stringStringHashMap.put(o,property);
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
          return stringStringHashMap;
    }

这就是Properyies文件的读取!小伙伴赶快试一试吧!

转载于:https://www.cnblogs.com/cainiaodongdong/p/8179043.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值