zoukankan      html  css  js  c++  java
  • C# ini文件操作帮助类

     1 public class IniConfigHelper
     2 {
     3 // 声明INI文件的写操作函数 WritePrivateProfileString()
     4 
     5         [System.Runtime.InteropServices.DllImport("kernel32")]
     6         private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
     7 
     8         // 声明INI文件的读操作函数 GetPrivateProfileString()
     9         [System.Runtime.InteropServices.DllImport("kernel32")]
    10         private static extern int GetPrivateProfileString(string section, string key, string def, System.Text.StringBuilder retVal, int size, string filePath);
    11 
    12 
    13 
    14         private string sPath = null;
    15 
    16 
    17         public IniConfigHelper(string path)
    18         {
    19             this.sPath = path;
    20         }
    21 
    22         /// <summary>
    23         ///  section=配置节,key=键名,value=键值,path=路径  
    24         /// </summary>
    25         /// <param name="section"></param>
    26         /// <param name="key"></param>
    27         /// <param name="value"></param>
    28         public void Write(string section, string key, string value)
    29         {
    30             // section=配置节,key=键名,value=键值,path=路径  
    31 
    32             WritePrivateProfileString(section, key, value, sPath);
    33         }
    34         
    35 
    36         public string ReadValue(string section, string key)
    37         {
    38             // 每次从ini中读取多少字节
    39             System.Text.StringBuilder temp = new System.Text.StringBuilder(255);
    40             // section=配置节,key=键名,temp=上面,读取该键名的值最大长度,path=路径
    41             GetPrivateProfileString(section, key, "", temp, 255, sPath);
    42             return temp.ToString();
    43         }
    44 
    45     }
  • 相关阅读:
    简单后台登录逻辑实现Controller
    自学semantic UI个人博客首页模板
    Spring Boot日志处理
    Thymeleaf静态资源引入方式及公共页面代码抽取
    一个简单SpringBoot应用的pom.xml文件
    Spring Boot入门程序
    easyuUI实现客户分页显示逻辑分析
    easyui自学模板代码
    网络协议-webService协议
    【转】彻底搞透Netty框架
  • 原文地址:https://www.cnblogs.com/MichaelJson/p/12894812.html
Copyright © 2011-2022 走看看