C#常用操作类库二(ini配置文件读写)

C#常用操作类库二(ini配置文件读写)

 
public  
class IniHelper

    {

         
//
文件INI名称 

        
public 
string Path;

        
/**/
///
/声明读写INI文件的API函数 

         [DllImport(

kernel32
)]

        
private 
static 
extern 
long WritePrivateProfileString(
string section, 
string key, 
string val, 
string filePath);

         [DllImport(

kernel32
)]

        
private 
static 
extern 
int GetPrivateProfileString(
string section, 
string key, 
string def, StringBuilder retVal, 
int size, 
string filePath);

        
//
类的构造函数,传递INI文件名 

         
public IniHelper(
string inipath)

        {

            
//
 
            

//
 TODO: Add constructor logic here 
            

//
 

             Path = inipath;

         }

        
//
写INI文件 

        
public 
void WriteValue(
string section, 
string key, 
string value)

        {

             WritePrivateProfileString(section, key, value, 
this.Path);

         }

        
//
读取INI文件指定 

        
public 
string ReadValue(
string section, 
string key)

        {

             StringBuilder temp = 
new StringBuilder(
255);

            
int i = GetPrivateProfileString(section, key, 
“”, temp, 
255
this.Path);

            
return temp.ToString();

         }

        
/**/
///
 
<summary>

        

///
 验证文件是否存在
        

///
 
</summary>

        

///
 
<returns>
布尔值
</returns>

        
public 
bool ExistFile()

        {

            
return File.Exists(
this.Path);

         }

        
///
 
<summary>

        

///
 删除ini文件下所有段落
        

///
 
</summary>

        
public     
void ClearAllSection()

        {

            WriteValue(
null
null
null);

        }

        
///
 
<summary>

        

///
 删除ini文件下personal段落下的所有键
        

///
 
</summary>

        

///
 
<param name=”Section”></param>

        
public   
void ClearSection(
string Section)

        {

            WriteValue(Section, 
null
null);

        }

    }

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/110445.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Hexo-Matery主题细致美化

    Hexo-Matery主题细致美化Hexo-Matery主题美化在一番瞎改js代码后,终于无法忍受next主题,于是愤然投入Matery大家庭,结果证明,香!下面是我记录的配置Matery主题的流程,仅供后来的师傅们参考。大家可以来我Hexo博客主页看看具体效果我的小站下载安装Matery主题首先在hexo官网主题里面搜索Matery主题点击进入作者大大的github,然后下载master分支的最新稳定版的代码,解压缩后将hexo-theme-matery的文件夹重命名为matery,复制到Hexo的theme

    2022年5月19日
    54
  • android开发之AIDL用法_进程间通信原理详解

    转自http://blog.csdn.net/saintswordsman/article/details/5130947欢迎阅读本文,你能关注本文,你知道你需要进程间通信、需要AIDL(以及Binder),那么可以默认你对这些概念已经有了一些了解,你(大致)知道它们是什么,它们有什么用,所以为了节约大家的眼力和时间,在此我不复制粘贴网上泛滥的博客或者翻译冗长的android文档。

    2022年3月10日
    36
  • goland 2021.5 激活码(最新序列号破解)

    goland 2021.5 激活码(最新序列号破解),https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月19日
    151
  • 在eclipse上修改tomcat内存大小

    在eclipse上修改tomcat内存大小

    2021年7月16日
    53
  • python df.iloc_python中loc

    python df.iloc_python中locstackoverflow原文:pandasilocvsixvslocexplanation;howaretheydifferent?在pandas0.20.0及以上版本,ix已经被loc和iloc取代了,因此不讨论它。前提,简单介绍一下它俩:–loc利用index的名称,来获取想要的行(或列)。–iloc利用index的具体位置(所以它只能是整数型参数),…

    2022年10月9日
    0
  • idea2021.4.14 mac版激活码_通用破解码

    idea2021.4.14 mac版激活码_通用破解码,https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月15日
    47

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号