How to load a resource bundle from a file resource in Java?

前端 未结 14 874
没有蜡笔的小新
没有蜡笔的小新 2020-11-28 08:19

I have a file called mybundle.txt in c:/temp -

c:/temp/mybundle.txt

How do I load this file into a java.util.Res

14条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-28 09:11

    public class One {
    
        private static One one = null;
    
        Map configParameter = Collections.synchronizedMap(new HashMap());
    
        private One() {
            ResourceBundle rb = ResourceBundle.getBundle("System", Locale.getDefault());
    
            Enumeration en = rb.getKeys();
            while (en.hasMoreElements()) {
                String key = (String) en.nextElement();
                String value = rb.getString(key);
                configParameter.put(key, value);
    
            }
        }
    
        public static One getInstance() {
            if (one == null) {
                one= new One();
            }
    
            return one;
    
        }
    
        public Map getParameter() {
    
            return configParameter;
        }
    
    
    
        public static void main(String[] args) {
            String string = One.getInstance().getParameter().get("subin");
            System.out.println(string);
    
        }
    }
    

提交回复
热议问题