Populating a HashMap with entries from a properties file

前端 未结 5 1193
南笙
南笙 2020-12-14 08:45

I want to populate a HashMap using the Properties class.
I want to load the entries in the .propeties file and then copy it into

5条回答
  •  伪装坚强ぢ
    2020-12-14 09:44

    public static Map getProperty()
        {
            Properties prop = new Properties();
            Mapmap = new HashMap();
            try
            {
                FileInputStream inputStream = new FileInputStream(Constants.PROPERTIESPATH);
                prop.load(inputStream);
            }
            catch (Exception e) {
                e.printStackTrace();
                System.out.println("Some issue finding or loading file....!!! " + e.getMessage());
    
            }
            for (final Entry entry : prop.entrySet()) {
                map.put((String) entry.getKey(), (String) entry.getValue());
            }
            return map;
        }
    

提交回复
热议问题