您的位置:首页 > 编程语言 > Java开发

java使用Properties类生成配置文件

2013-07-08 11:03 344 查看
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"));
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐