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;
            }
  • 相关阅读:
    UE4 Cel Shading(卡通渲染)
    UE4 常用数学
    锈迹材质全流程实例:Blender-》SP-》UE4
    ue4 优化建议与经验
    VisualStudio开发UE4工程设置
    Procedural Mesh Component in C++:Getting Started
    Java容器有哪些?
    java 连接mongodb
    mongodb 系列 ~ mongo 用户验证系列
    mongodb连接认证失败
  • 原文地址:https://www.cnblogs.com/zhumeng1582/p/3425795.html
Copyright © 2011-2022 走看看