Apache Commons Configuration
依赖
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
<version>1.10</version>
</dependency>
public void editIni() {
String iniFilePath = "xxx";
try {
//创建文件对象
HierarchicalINIConfiguration hierarchicalINIConfiguration = new HierarchicalINIConfiguration(iniFilePath);
//获取指定节点对象
SubnodeConfiguration section = hierarchicalINIConfiguration.getSection("xx");
//编辑指定key
section.setProperty("xx", "8");
//保存修改
hierarchicalINIConfiguration.save();
} catch (ConfigurationException e) {
e.printStackTrace();
}
}
Apache Commons Configuration2
依赖
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-configuration2</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.4</version>
</dependency>
public void editIni() {
String filename = "xxxx";
// 默认直接读取类路径下的配置文件
try { Configurations configs = new Configurations();
INIConfiguration ini = configs.ini(new File(filename));
SubnodeConfiguration section = ini.getSection("xxx");
section.setProperty("xx","5");
FileWriter fileWriter = new FileWriter(filename);
ini.write(fileWriter);
fileWriter.close();
ini.clear();
} catch (Exception e) {
// Something went wrong
e.printStackTrace();
}
}
标签:section,commons,Commons,ini,Apache,new
From: https://www.cnblogs.com/zuitaiping/p/17798141.html