zoukankan      html  css  js  c++  java
  • C# 读写Ini 文件

    代码如下:

     

    1. # 读写 Ini 文件   
    2. using System.Runtime.InteropServices;  
    3. public class IniFile  
    4. {  
    5.     private string path;  
    6.  
    7.     public IniFile(string iniPath)  
    8.     {  
    9.         this.path = iniPath;  
    10.     }  
    11.  
    12.     [DllImport("kernel32")]  
    13.     private static extern int GetPrivateProfileString  
    14.         (string section, string key, string def, StringBuilder retVal, int size, string filePath);  
    15.     [DllImport("kernel32")]  
    16.     private static extern long WritePrivateProfileString  
    17.         (string section, string key, string val, string filePath);  
    18.  
    19.     public string IniReadValue(string section, string key)  
    20.     {  
    21.         try 
    22.         {  
    23.             StringBuilder retVal = new StringBuilder(0xff);  
    24.             if (GetPrivateProfileString(section, key, "", retVal, 0xff, this.path) == 0)  
    25.             {  
    26.                 return string.Empty;  
    27.             }  
    28.             return retVal.ToString();  
    29.         }  
    30.         catch (Exception exception)  
    31.         {  
    32.             return exception.ToString();  
    33.         }  
    34.     }  
    35.  
    36.     public void IniWriteValue(string Section, string Key, string Value)  
    37.     {  
    38.         WritePrivateProfileString(Section, Key, Value, this.path);  
    39.     }  
  • 相关阅读:
    strcat strcpy 使用出现的问题汇总
    MySql Host is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts' 解决方法
    nginx 设置反响代理实现nginx集群
    js 去掉字符串最后一个字符
    二维数组 获取某键值集合
    oracle 序列
    递归数据查询
    oracle 递归查询
    jQuery EasyUI API 中文文档
    SecureCRT使用的技巧 键盘修改
  • 原文地址:https://www.cnblogs.com/wwwzzg168/p/3569064.html
Copyright © 2011-2022 走看看