【笔记——Java】读取properties文件

假设有一个test.pjroperties文件等待读取

 1         Properties pro = new Properties();
 2         InputStream in = getClass().getResourceAsStream("test.properties");
 3         Map<String,String> map = new HashMap<>();
 4         try {
 5             pro.load(in);
 6             Enumeration<?> en = pro.propertyNames();
 7             while(en.hasMoreElements()){
 8                 String key = (String)en.nextElement();
 9                 String value = pro.getProperty(key);
10                 map.put(key, value);
11             }
12         } catch (IOException e) {
13             // TODO Auto-generated catch block
14             e.printStackTrace();
15         }

 

posted @ 2014-12-21 15:37  cirno_9  阅读(248)  评论(0)    收藏  举报