zoukankan      html  css  js  c++  java
  • C# 读取ini文件,读不出来原因

    先赋上相关读取ini文件代码

    public class INIHelper
        {
            public string inipath;
            [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 INIHelper(string INIPath)
            {
                inipath = INIPath;
            }
    
            public void set(string Section, string Key, string Value)
            {
                WritePrivateProfileString(Section, Key, Value, this.inipath);
            }
            /// <summary> 
            /// 读出INI文件 
            /// </summary> 
            /// <param name="Section">项目名称(如 [TypeName] )</param> 
            /// <param name="Key">键</param> 
            public string ReadInivalue(string Section, string Key)
            {
                StringBuilder temp = new StringBuilder(500);
                int i = GetPrivateProfileString(Section, Key, "", temp, 500, this.inipath);
                return temp.ToString();
            }
            /// <summary> 
            /// 验证文件是否存在 
            /// </summary> 
            /// <returns>布尔值</returns> 
            public bool ExistINIFile()
            {
                return File.Exists(inipath);
            }
    
    
            
        }
    

      调用以上方法的代码

    INIHelper iniHelper = new INIHelper(Application.StartupPath + "\Level.ini");
    private void ConfigureShowHighFrm_Load(object sender, EventArgs e)
            {
                if (iniHelper.ReadInivalue("config", "high") == "1")
                    checkBox1.Checked = true;
                else
                    checkBox1.Checked = false;
    
                if (iniHelper.ReadInivalue("config", "hit") == "1")
                    checkBox2.Checked = true;
                else
                    checkBox2.Checked = false;
    
                if (iniHelper.ReadInivalue("config", "low") == "1")
                    checkBox3.Checked = true;
                else
                    checkBox3.Checked = false;
            }
    

      然后再看ini文件截图

    不知道看到没有这个图片,这个就是ini文件第一行必须是空格,否则读不出来哦!!!

  • 相关阅读:
    send和sendmsg性能测试【sendmsg和send的性能基本一样,并没有得到优化】
    send和sendmsg性能测试
    SparkException: Master removed our application
    大数据入门:各种大数据技术介绍
    78 subsets
    C、C ++的内存模型
    将博客搬至CSDN
    适配器模式
    建造者(Builder)模式
    桥接模式
  • 原文地址:https://www.cnblogs.com/Anders888/p/3573104.html
Copyright © 2011-2022 走看看