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

    // 声明INI文件的写操作函数 WritePrivateProfileString()
            [System.Runtime.InteropServices.DllImport("kernel32")]
            private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
    
            // 声明INI文件的读操作函数 GetPrivateProfileString()
            [System.Runtime.InteropServices.DllImport("kernel32")]
            private static extern int GetPrivateProfileString(string section, string key, string def, System.Text.StringBuilder retVal, int size, string filePath);
            public static string WriteValue(string section, string key, string value)
            {
                string sPath = getIniFilePath();
    
                long i = WritePrivateProfileString(section, key, value, sPath);
                if (i == 0)
                    return "fail";
                else
                    return "success";
    
            }
            public static string ReadValue(string section, string key)
            {
                string sPath = getIniFilePath();
                StringBuilder temp = new StringBuilder(255);
                int i = GetPrivateProfileString(section, key, "", temp, 255, sPath);
                if (i == 0)
                    return "fail";
                else
                    return temp.ToString();
            }
    
            private static string getIniFilePath()
            {
                string sPath = null;
                if (System.Environment.CurrentDirectory == AppDomain.CurrentDomain.BaseDirectory)//windows应用程序则相等
                    sPath = AppDomain.CurrentDomain.BaseDirectory;
                else
                    sPath = AppDomain.CurrentDomain.BaseDirectory + @"config.ini";
                return sPath;
            }
  • 相关阅读:
    51nod贪心算法入门-----完美字符串
    HDU6030----矩阵快速幂
    O(n)求1~n的逆元
    (四)添加签到奖励功能
    (三)开始在OJ上添加签到功能
    (二)OJ的主要文件
    (一)在linux上ubuntu搭建hustOJ系统
    CF 148A Insomnia cure
    lower_bound和upper_bound
    C++ string的常用功能
  • 原文地址:https://www.cnblogs.com/zhumeng1582/p/3425795.html
Copyright © 2011-2022 走看看