zoukankan      html  css  js  c++  java
  • 读写ini

    string file = Application.StartupPath + "\config.ini";
            public Form1()
            {
                InitializeComponent();
            }
            [DllImport("kernel32")]
            private static extern bool WritePrivateProfileString(string section, string key, string val, string filePath);
    
            [DllImport("kernel32")]
            private static extern int GetPrivateProfileString(string section, string key, string def, byte[] retVal, int size, string filePath);
            private void button1_Click(object sender, EventArgs e)
            {
                string s = ReadINI("config", "user");
                label1.Text = s;
            }
    
            private void button2_Click(object sender, EventArgs e)
            {            
                WritePrivateProfileString("config", "user", "lake.liu", file);
                WritePrivateProfileString("config", "name", "lake", file);
                WritePrivateProfileString("config", "age", "40", file);
            }
    
            public string ReadINI(string section, string key)
            {
                byte[] Buffer = new byte[128];
                int bufLen = GetPrivateProfileString(section, key, "", Buffer, Buffer.GetUpperBound(0), file);
                string s = Encoding.GetEncoding(0).GetString(Buffer);
                s = s.Substring(0, bufLen);
                return s.Trim();
            }

    读写ini 代码参考

  • 相关阅读:
    五分钟搭建起一个包含CRUD功能的JqGrid表格
    TDD学习笔记【六】一Unit Test
    CQRS
    开源一个vue2的tree组件
    权限管理[Linux]
    文件管理[Linux]
    查看文本[Linux]
    常用命令[Linux]
    文件管理[Linux]
    状态机工作流
  • 原文地址:https://www.cnblogs.com/lakeliu/p/11969986.html
Copyright © 2011-2022 走看看