一、设计理念

属性配置文件:只需要改文件中的内容

image.png
image.png

  1. package IO.jia.Properties;
  2. import java.io.FileNotFoundException;
  3. import java.io.FileReader;
  4. import java.io.IOException;
  5. import java.util.Properties;
  6. public class IoPropertiesTest01 {
  7. public static void main(String[] args) throws IOException {
  8. //新建一个输入流对象
  9. FileReader reader = new FileReader("io/src/IO/jia/Properties/userinfo.properties");
  10. //新建一个Map集合
  11. Properties pro = new Properties();
  12. //调用Properties的load方法将文件的数据加载到Map集合中
  13. pro.load(reader);
  14. //通过key获取value
  15. String username = pro.getProperty("username");
  16. System.out.println(username);
  17. }
  18. }