对*.ini文件的增删改查
文件的格式有很多种 *.ini 一般是带一个齿轮的配置文件,这个文件的操作有专门的类库进行处理不行自己硬编码 ini4j.jar
这个jar包专门封装了处理*.ini文件的方法。
1 public interface IParaManager { 2 public int getKey(String section, String key, CInt value); 3 public int getkey(String section, String key, CString value); 4 public int getkey(String section, String key, CDouble value); 5 public Map<String, String> getGeys(String section); 6 public int setKey(String section, String key, String value); 7 8 }
1 public class CFileParaManagerNew implements IParaManager { 2 3 private Logger logger = Logger.getLogger(CFileParaManager.class); 4 Wini ini = null; 5 public CFileParaManagerNew(String fileName) throws Exception{ 6 String path = System.getProperty("user.dir");//参数待定7 String filePath = path + File.separator +"resources" +File.separator + fileName;8 logger.debug("filePath is" + filePath);9 Config config = new Config();10 config.setMultiSection(true);11 ini = new Wini(new File(filePath)); 12 } 13 @Override 14 public int getKey(String section, String key, CInt value) { 15 logger.debug("CFileParaManager getKey CInt start"); 16 String str = Integer.valueOf(value.get()).toString(); 17 CString cString = new CString(); 18 cString.set(str); 19 int num = getkey(section, key, cString); 20 if (num != 0) { 21 logger.debug("CFileParaManager getKey CInt fail"); 22 return -1; 23 } 24 int val = Integer.parseInt(cString.get()); 25 value.set(val); 26 logger.debug("CFileParaManager getKey CInt end"); 27 return 0; 28 } 29 30 @Override 31 public int getkey(String section, String key, CString value) { 32 logger.debug("CFileParaManager getKey CString start"); 33 if (null == section || null == key) { 34 logger.debug("CFileParaManager getKey CString start section or key or value is null"); 35 return -1; 36 } 37 logger.debug("section is" + " " + section + " "+ "key is" + " " + key); 38 Config config = new Config(); 39 config.setMultiSection(true); 40 String reValue = ini.get(section, key, String.class); 41 if (reValue == null) { 42 logger.debug("reValue is null"); 43 return -1; 44 } 45 value.set(reValue); 46 return 0; 47 48 } 49 50 @Override 51 public int getkey(String section, String key, CDouble value) { 52 logger.debug("CFileParaManager getKey CDouble start"); 53 String str = Double.valueOf(value.get()).toString(); 54 CString cString = new CString(); 55 cString.set(str); 56 int num = getkey(section, key, cString); 57 if (num != 0) { 58 logger.debug("CFileParaManager getKey CDouble fail"); 59 return -1; 60 } 61 double val = Double.parseDouble(cString.get()); 62 value.set(val); 63 logger.debug("CFileParaManager getKey CDouble end"); 64 return 0; 65 66 } 67 @Override 68 public Map<String, String> getGeys(String section) { 69 logger.debug("CFileParaManager getGeys section start"); 70 if (section == null || section.length() == 0) { 71 logger.debug("CFileParaManager getGeys section is not normal"); 72 } 73 Map<String, String> sections = ini.get(section); 74 logger.debug("CFileParaManager getGeys section end"); 75 return sections; 76 } 77 @Override 78 public int setKey(String section, String key, String value) { 79 logger.debug("CFileParaManager setKey section start"); 80 if (section == null || key == null || value == null) { 81 logger.debug("setction or key or value is not normal"); 82 return -1; 83 } 84 //ini.add(section, key, value); 85 logger.debug("CFileParaManager setKey section end"); 86 //如果section用的话就是修改 没有就是创建 87 ini.put(section, key, value); 88 //2018/10/9 这段代码不加上修改不起任何作用89 try {90 ini.store();91 } catch (IOException e) {92 // TODO Auto-generated catch block93 e.printStackTrace();94 } 95 //ini.get(section, key); 96 97 return 0; 98 } 99 100 } 参考的wiki:https://www.vdisk.cn/ini4j/(ini4j.jar 资源的汇总)https://blog.csdn.net/wwkms/article/details/48973307(对properties文件的增删改查)https://blog.csdn.net/xulingqiang/article/details/25059931(对*ini 文件的操作 两个工具方法 一个原始方法)https://blog.csdn.net/aaronhadoop/article/details/49994413#(*ini文件操作的入门小demo)https://www.programcreek.com/java-api-examples/index.php?api=org.ini4j.InvalidFileFormatException(没有看懂 但demo确实很多)
转载于:https://www.cnblogs.com/chengxuzhijia/p/9762239.html
对*.ini文件的增删改查相关推荐
- java对xml文件做增删改查------摘录
java对xml文件做增删改查 package com.wss; import java.io.File; import java.util.ArrayList; import java.util.L ...
- Python文件操作-文件的增删改查
需求:对文件进行增删改查 由于时间原因,本次代码没有增加任何注释,如有疑问,请联系编辑者:闫龙 其实我也是醉了,看着这些个代码,我脑袋也特么大了,没办法,大神说了,不让用新知识,只可以使用学过的,所以 ...
- mybatis3.1-[topic-16-17]-映射文件_增删改查_insert_获取自增主键的值
笔记要点 出错分析与总结 /**测试第16章的增,删,改 的内容* 错误1: <insert id="addEmp" parameterType="com.bean ...
- 一文入门Golang文件操作——增删改查【超基础】
目录 前言 正文 增--创建文件 改--修改文件 查--查询文件 删--删除文件 结尾 前言 目前,Golang 可以认为是服务器开发语言发展的趋势之一,特别是在流媒体服务器开发中,已经占有一席之地. ...
- dom4j创建、解析xml文件(增删改查)
先对xml文件进行解析,xml文件如下图所示 <?xml version="1.0" encoding="UTF-8"?> <?eclipse ...
- Java实现对文件的增删改查操作
1.建立一个文件存放数据 2.首先创建一个person类,声明姓名,年龄. 下面展示一些 内联代码片. class Person {String name;int age;public String ...
- sqlite3打开本地.db文件及增删改查语句
1.打开数据库文件(xxx.db即为数据库文件) 进入存放db文件的路径下,输入sqlite3,再输入.open xxx.db(或者直接sqlite3 xxx.db): 输入.tables 查看数据库 ...
- python增删改查csv文件_Python增删改查文件
#!/usr/bin/env python # -*- coding:utf-8 -*- # author:Erik Chan # datetime:2018/12/27 9:29 # softwar ...
- python增删改查csv文件_【练习】Python第四次:实现对文件的增删改查
import os #os包含改名和删除文件函数 def file_handler(backend_data,res = None,type='fetch'):if type == 'fetch': ...
- 在plist文件中增删改查
plist文件是一种轻量级大数据存储方式,它的全名为PropertyList,即属性列表文件,它是一种用来存储串行化后的对象的文件.Plist文件是以key-value的方式来存取数据的. 创建pli ...
最新文章
- 服务器信号为970101,cDIN_EN_ISO_306.970101精选.pdf
- (转载)Web 开发人员需知的 Web 缓存知识
- Cannot add or update a child row: a foreign key constraint fails (`university`.`instructor`, CONSTRA
- [Domino]Java访问Domino必需配置的服务器设置
- 对称机密算法与非对称机密算法
- unity里如何在点击UI时,避免触发游戏内操作。
- ajax瀑布流 dede,dedecms加载更多,无限下拉瀑布流插件
- java之重定向与转发
- php创建游戏房间思路,php设计模式之建造器模式分析【星际争霸游戏案例】
- python怎么设置为中文-python怎么变成中文版
- Unity: 打飞碟Adapter版
- 御用导航提示提醒_AR实景导航,让你安全驾驶,不再“绕弯”
- kudu底层存储引擎的数据组织方式
- Dropshipping在Facebook广告语怎么写?
- java2d方法_Java SunGraphics2D.fillRect方法代码示例
- Nginx Rewrite的讲解(从新手村到小有成就7)
- Udacity数据分析(进阶)-Prosper 贷款数据分析
- Groovy探索之MOP 十五 方法名的动态性(2)
- 个人如何打破部门墙_做事要有霸气
- 【LeetCode】1655. Distribute Repeating Integers 分配重复整数