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