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.     }  
  • 相关阅读:
    正则表达式去掉文件路径中的特殊字符
    用MD5加密字符串
    FTP响应码
    简述MD5校验文件
    SQLServer存储过程帮助类
    MySql数据库帮助类:DbHelperMySQL
    SQLServer数据库帮助类:DbHelperSQL
    基于Window10搭建android开发环境
    Ubuntu14.04搭建Android O编译环境
    Sublime text 3搭建Python开发环境及常用插件安装
  • 原文地址:https://www.cnblogs.com/wwwzzg168/p/3569064.html
Copyright © 2011-2022 走看看