- /////////////////////////直接遍历/////////////////////////
- public class TestProperties {
- public static void main(String[] args) throws FileNotFoundException, IOException {
- Properties p = new Properties();
- p.load(new FileInputStream(new File("c:\\\\p.properties")));
- Iterator itr = p.entrySet().iterator();
- while (itr.hasNext()){
- Entry e = (Entry)itr.next();
- System.out.println(e.getKey() + ": " + e.getValue());
- }
- }
- }
- /////////////////////////////////////////////////////////////////
- /**
- * 将properties属性文件转换成list类型数据
- *
- * @param fileName
- * properties属性文件名
- * @return List集合
- */
- public static List<Entry<Object, Object>> propToList(String fileName) {
- Properties props = readPorp(fileName);
- Iterator<Entry<Object, Object>> it = props.entrySet().iterator();
- List<Entry<Object, Object>> list = new ArrayList<Entry<Object, Object>>();
- while (it.hasNext()) {
- Entry<Object, Object> entry = (Entry<Object, Object>) it.next();
- list.add(entry);
- // logger.info(entry.getKey()+" : "+entry.getValue());
- }
- return list;
- }
- //该片段来自于http://www.codesnippet.cn/detail/301220138319.html
来源: http://www.codesnippet.cn/detail/301220138319.html