正文

Properties 持久的属性集的实例详解(propertities)太疯狂了

文章摘要

这篇文章介绍了一种通过使用Properties类从文件中读取属性值的方法。文章详细解释了如何使用`readValue`方法读取特定键的值,并通过`readProperties`方法读取所有键值对。文章还提到了如何从输入流中读取属性列表,并使用`BufferedInputStream`来提高读取效率。需要注意的是,文章中提到建议使用ClassLoader加载属性文件,但实际代码中使用了`read`方法而不是`load`方法。文章整体重点在于展示如何高效地读取和处理属性文件。

 // 根据key读取value public void readValue(String filePath, String key) { Properties props=new Properties(); InputStream in=new BufferedInputStream(new FileInputStream(filePath)); //Thread.currentThread().getContextClassLoader().getResourceAsStream(“eop.properties”); props.load(in); // 从输入流中读取属性列表(键和元素对) String value=props.getProperty(key); } // 读取properties的全部信息 public static void readProperties(String filePath) { Properties props=new Properties(); InputStream in=new BufferedInputStream(new FileInputStream(filePath)); props.load(in); Enumeration en=props.propertyNames(); while (en.hasMoreElements()) { String key=(String) en.nextElement(); String value=props.getProperty(key);   } }