zoukankan      html  css  js  c++  java
  • C# C/S 结构操作Ini系统文件

    Winfrom 开发时,有时会将一些系统某个设置保存到Ini 类型的文件中.下面提供操作Ini 文件的代码:

     public static class IniFiles
        {
            [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);
            public static string FilePath;
    
            /// <summary>
            /// 写入Ini文件
            /// </summary>
            /// <param name="section">项目名称(如 [TypeName] )</param>
            /// <param name="key"></param>
            /// <param name="value"></param>
            public static void IniWriteValue(string section, string key, string value)
            {
                WritePrivateProfileString(section, key, value, FilePath);
            }
    
            /// <summary>
            /// 读出Ini文件
            /// </summary>
            /// <param name="section">项目名称(如 [TypeName] )</param>
            /// <param name="key"></param>
            public static string IniReadValue(string section, string key)
            {
                StringBuilder temp = new StringBuilder(500);
                int i = GetPrivateProfileString(section, key, "", temp, 500, FilePath);
                return temp.ToString();
            }
    
            /// <summary>
            /// 验证文件是否存在
            /// </summary>
            /// <returns>布尔值</returns>
            public static bool ExistIniFile()
            {
                return File.Exists(FilePath);
            }
        }
    View Code
  • 相关阅读:
    339. Nested List Weight Sum
    41. First Missing Positive
    366. Find Leaves of Binary Tree
    287. Find the Duplicate Number
    130. Surrounded Regions
    ubuntu18.04安装mongodb4.4
    阿里dataX配置使用
    MySQL主从同步简单介绍&配置
    阿里yugong配置使用
    ubuntu编译安装mysql
  • 原文地址:https://www.cnblogs.com/wjbobo/p/4243859.html
Copyright © 2011-2022 走看看