一、test.properties文件
如下图的键值对,我们可以把某些配置信息写入到这个文件中,项目去读取配置信息
二、读取步骤
public class Test {
public static void main(String[] args) throws IOException {
Properties pro = new Properties();
//pro对象是一个map集合--内存
//1.像以前的map集合一样使用
//put,get,remove,keySet,entrySet,size
//2.能将properties文件中的key-value信息加载到我们的集合里
//创建一个输入流(读取指定文件中的信息)
InputStream is = Thread.currentThread()
.getContextClassLoader()
.getResourceAsStream("test.properties");
//加载到pro对象里面
pro.load(is);
Enumeration en = pro.propertyNames();
while (en.hasMoreElements()) {
String key = (String) en.nextElement();
String value = pro.getProperty(key);
System.out.println(key + "--" + value);
}
}
}