java使用Properties类生成配置文件

来源:互联网 发布:玩转linux系统 编辑:程序博客网 时间:2024/06/03 23:54

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"));


原创粉丝点击