配置文件Properties对象
1.说明
一般我们在Java中会对应一个 .properties 文件,且这个文件一般会保存一些配置信息。
比如:数据库信息(ip地址、端口号、用户名、密码)
2.格式
这个对象的基本使用跟 Map<String,String> 差不多,
注释格式为:#注释内容
key 和value值写法: key =value
3.对象使用
Properties properties = new Properties();
properties.load(new FileReader("D:\\properties.properties");
//load过后,properties 变量中,就已经读取了配置文件中的数据
数据获取
String filePath = properties.getProperty("admin");
//获取456
可以设置如果没有找到,则返回默认值
String ccc = properties.getProperty("ccc","xyz");
设置值,如果存在则会覆写
properties.setProperty("xyz", "qpw");
properties.store(new FileWriter("d:\\haha.properties"), "随便写的注释内容");