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.     }  
  • 相关阅读:
    前端
    小程序开发
    mpvue开发小程序
    (33)Vue购物车
    Vue的使用你学会了吗?
    (32)Vue模板语法
    (31)Vue安装
    (3)Angular的开发
    (2)Angular的开发
    (1)Angular的开发
  • 原文地址:https://www.cnblogs.com/wwwzzg168/p/3569064.html
Copyright © 2011-2022 走看看