package test15;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.util.Properties;/*** Created By Intellij IDEA** @author Xinrui Yu* @date 2021/12/4 16:09 星期六*/public class Application {public static void main(String[] args) throws Exception {Properties properties = new Properties();FileInputStream fileInputStream = new FileInputStream("src/test15/jdbc.properties");properties.load(fileInputStream);fileInputStream.close();String name = properties.getProperty("name");String password = properties.getProperty("password");System.out.println("name:" + name);System.out.println("password:" + password);}}
Map的一个实现类:Properties常用来读取配置文件中的配置信息
首先通过load() 方法,将配置文件读取到对象中,然后再去对象中获取需要的配置信息。
注意:properties 只允许存储 string 类型的 key 和 string 类型的 value
