首页 > 其他分享 >Apache Commons Configuration/Apache Commons Configuration2 编辑ini文件

Apache Commons Configuration/Apache Commons Configuration2 编辑ini文件

时间:2023-10-30 16:24:56浏览次数:30  
标签:section commons Commons ini Apache new

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

相关文章

  • Soil salinization 土地盐碱化
    Thedefinitionofsoil salinization定义Soil salinization refers to the process of salt accumulation in the surface soil after the salt from the bottom soil or groundwater rises to the surface with the capillary water. In brie......
  • Baize_h1mini六足机器人零件准备
    导航在这里:Baize_H1mini六足机器人制作教程(开源)_ros六足机器人教程视频教程:手把手带你做开源六足机器人(3D图纸+硬件图纸+软件源码+制作说明书在视频下方自取!)_哔哩哔哩_bilibili你现在在地图的红色字体位置(走到终点就制作完成了):重要提示:自己使用打印机打印零件时,对于新手来说肯定......
  • Apache Dubbo 3.0之服务发现
    服务发现,即消费端自动发现服务地址列表的能力,是微服务框架需要具备的关键能力,借助于自动化的服务发现,微服务之间可以在无需感知对端部署位置与IP地址的情况下实现通信。实现服务发现的方式有很多种,Dubbo提供的是一种Client-Based的服务发现机制,通常还需要部署额外的第三方注册......
  • MinIO 高性能分布式存储最新版单机与分布式部署
    目录一、概述二、单机部署(单主机,多硬盘模式)1)磁盘初始化2)创建服务启动用户并设置磁盘属主3)下载minio安装包4)修改配置5)配置systemctl启动6)客户端工具mc三、分布式集群部署(多主机、多硬盘模式)1)磁盘初始化2)创建服务启动用户并设置磁盘属主3)下载minio安装包4)修改配置5)配置syste......
  • minio简介
     一、简介 MinIO是一个基于ApacheLicensev2.0开源协议的对象存储服务。它兼容亚马逊S3云存储服务接口,非常适合于存储大容量非结构化的数据,例如图片、视频、日志文件、备份数据和容器/虚拟机镜像等,而一个对象文件可以是任意大小,从几kb到最大5T不等。官网:https://www......
  • jupyter notebook启动出错:Bad config encountered during initialization:/ No such
    问题:安装anaconda后,使用condainstalljupyternotebook安装jupyter,出现Badconfigencounteredduringinitialization:Nosuchnotebookdir:解决方法如下:在开始菜单找到AnacondaPromt并打开。在AnacondaPromt输入:jupyternotebook--generate-config根据弹出的地址找到jupyter......
  • [ApacheCommon组件使用-IO]关于JavaIO,相当输入的一个工具就是ApacheCommon-IO
    1.首先,如果你使用的是maven或者gradle建立的项目,maven只需要<!--https://mvnrepository.com/artifact/commons-io/commons-io--><dependency><groupId>commons-io</groupId><artifactId>commons-io</artifactId>......
  • [ABC299G] Minimum Permutation
    ABC229G洛谷链接atcoder链接容易发现如果最终答案有两个相邻的数\(b_i,b_{i+1}\)满足\(b_i>b_{i+1}\)且\(b_i\)之后出现过,则显然可以找到另一个不劣的答案不满足这个性质先说一个错误的结论:从前往后考虑,用链表维护答案,对于加入的一个数\(a_i\),如果之前在\(a_j\)出现......
  • org.apache.subversion.javahl.ClientException: The working copy needs to be upgra
    eclipse不编译,每次修改代码控制台都显示错误svn:Theworkingcopyneedstobeupgradedorg.apache.subversion.javahl.ClientException:Theworkingcopyneedstobeupgradedsvn:Workingcopy‘E:\aliyun-spirit\spiritmap0916′istooold(format10,createdbySubversi......
  • pve制作cloudinit windows
    参考网址:https://blog.csdn.net/feitianyul/article/details/113683909https://forum.proxmox.com/threads/windows-cloud-init-working.83511/https://foxi.buduanwang.vip/windows/1789.html/1、首先在pve上创建一个winodws虚拟机,创建完成后,添加硬件-->串行端口2、下载cl......