Properyies文件的读取

当我们使用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文件的读取!小伙伴赶快试一试吧!

posted @ 2018-01-02 20:35  菜鸟东东  阅读(225)  评论(0编辑  收藏  举报