• C#读写ini


    using System;
    using System.IO;
    using System.Runtime.InteropServices;
    using System.Text;
     
    namespace helper
    {
     
        /// <summary> 
        /// ini文件读与写 
        /// </summary> 
        public class ClsIniFile
        {
            //文件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 ClsIniFile(string inipath){ Path = inipath; }
            /// <summary>
            /// 写入INI文件
            /// </summary>
            /// <param name="Section">配置节</param>
            /// <param name="Key">键名</param>
            /// <param name="Value">键值</param>
            public void IniWriteValue(string Section, string Key, string Value)
            {
                WritePrivateProfileString(Section, Key, Value, this.Path);
            }
     
            /// <summary>
            /// 读取制定INI文件键值
            /// </summary>
            /// <param name="Section">配置节</param>
            /// <param name="Key">键名</param>
            /// <returns></returns> 
            public string IniReadValue(string Section, string Key)
            {
                StringBuilder temp = new StringBuilder(255);
                int i = GetPrivateProfileString(Section, Key, "", temp, 255, this.Path);
                return temp.ToString();
            }
        }
    }

    转载于:https://www.cnblogs.com/ruingking/p/7160601.html

  • 相关阅读:
    记录锁
    linux多线程同步pthread_cond_XXX条件变量的理解
    设置创建文件掩码遇到的问题
    函数的可重入和线程安全
    sigemptyset,sigfillset,sigaddset,sigdelset,sigismember,sigprocmask,sigpendmask作用
    嵌入式中断服务函数的一些特点
    linux alarm函数解除read write等函数的阻塞
    孤儿进程,僵死进程
    标准IO的缓冲问题
    《实用技巧》——让你的网站变成响应式的3个简单步骤
  • 原文地址:https://www.cnblogs.com/twodog/p/12139928.html
Copyright © 2020-2023  润新知