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

随心笔谈1年前 (2023)发布 admin
100 0


// 根据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);
  }
}

© 版权声明

相关文章