OI+Properties联合使用

it2023-07-03  73

OI+Properties

1.文件不需要改,不需要编译,服务器不需要重启,就可以拿到动态的信息 2.建议使用.properties结尾,这种文件称为属性配置文件 3.属性的配置文件value值重复,value会被覆盖

test.properties配置文化 usersname="zs" password=123456 package com; import java.io.*; import java.util.Properties; /** * 一次序列化多个对象 * 可以,可以将对象放在集合,序列化集合 */ public class Test { public static void main(String[] args) throws IOException { //创建输入流对象 FileReader f = new FileReader("mybatis001\\test.properties"); //新建map结合 Properties properties = new Properties(); //调用Properties对象的load方法将文件的数据加载到Map集合 properties.load(f); //通过key获取value String username = properties.getProperty("username"); System.out.println(username); String password = properties.getProperty("password"); System.out.println(password); } }
最新回复(0)