Properties类小结

创建properties文件

new 一个 resource bundle文件,只写文件名,
在文件中通过键值对的方式,写入配置信息

user=miko
pwd=123456
ip=168.10.25.1

注意:键值对不需要有空格,默认类型为String类型

键值对应用

1.创建properties对象
2.load:方法加载配置文件键值到properties对象
3.list:将数据显示到制定设备
4.getProperty(Key):通过键获取值
5.setProperty(Key.Value):设置键值对到properties对象
6.store(OutputStream/Writer,null)通过输出流保存properties文件,并将注释设为null.
如果用outputStream保存中文的话,会以unicode码的形式储存

		Properties properties = new Properties();
        properties.load(new FileReader("src\\mysql.properties"));
        properties.list(System.out);
        //properties.list(new PrintStream("d:\\checkmyspl.txt"));
        System.out.println("----------------");
        String user = properties.getProperty("user");
        String pwd = properties.getProperty("pwd");
        System.out.println("user="+user);
        System.out.println("pwd="+pwd);
        properties.setProperty("user","miko");
        properties.store(new FileWriter("src\\mysql.properties"),null);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值