1、生成 .xml 格式的配置文件:
1.1 生成配置文件
Properties properties = new Properties();//生成实例
properties.setProperty("qq", "com.tarena.factory.QQ");//设置键值 key----value
properties.storeToXML(new FileOutputStream("tarena.xml"), "k---v");//像新文件存储
1.2 加载配置文件
Properties properties2 = new Properties();
properties2.loadFromXML(new FileInputStream("tarena.xml"));
2、生成 .properties 格式的配置文件:
2.1 生成配置文件
Properties properties = new Properties();//生成实例
properties.setProperty("qq", "com.tarena.factory.QQ");//设置键值 key----value
properties.store(new FileOutputStream("tarena.properties"), "key===value");2.2 加载配置文件
Properties properties2 = new Properties();
roperties2.load(new FileInputStream("tarena.properties"));