需引入jar包
<!-- https://mvnrepository.com/artifact/commons-configuration/commons-configuration -->
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
<version>1.10</version>
</dependency>
PropertiesConfiguration config = new PropertiesConfiguration();
config.setEncoding("UTF-8");//编码
config.load("文件路径");//读取文件,如果不写这一步,那么setFileName文件将是空文件,然后存入我们设定的属性
config.setFileName("文件路径");
Iterator<String> keys = config.getKeys();
while(keys.hasNext()){
//如果存在,则调用next实现迭代
//Object-->Integer-->int
String key=keys.next();
if(key.split("_")[2].equals("*****"))//要修改的属性值
config.setProperty(key,"33333");
}
config.setProperty("****", "11111");
config.save();