遍历properties属性文件,历properties属性,////////////
分享于 点击 37715 次 点评:196
遍历properties属性文件,历properties属性,////////////
/////////////////////////直接遍历/////////////////////////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://byrx.net
用户点评