properties文件读取工具

public class PropertiesReader
{
    public Map<String,String> getProperties(){
        Properties pro=new Properties();
        Map<String ,String> map=new HashMap<String ,String>();
        try
        {
            //以流的形式读取properties文件
            InputStream in=getClass().getResourceAsStream("要读取的properties文件");
            pro.load(in);
            Enumeration en=pro.propertyNames();
            while(en.hasMoreElements()){
                String key= (String) en.nextElement();
                String property=pro.getProperty(key);
                map.put(key,property);
            }
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }return map;
    }
}

猜你喜欢

转载自blog.csdn.net/weixin_41657883/article/details/80889404