zoukankan      html  css  js  c++  java
  • C#操作.ini文件

    INI文件是一种按照特点方式排列的文本文件。

    每一个INI文件构成都非常类似,由若干段落(section)组成,

    在每个带括号的标题下面,是若干个以单个单词开头的关键词(keyword)和一个等号,

    等号右边的就是关键字对应的值(value)。其一般形式如下:
    [section1]
     keyword1=value1 
     keyword2=value2
     keyword3=value3
    [section2]
     keyword1=value1
     keyword2=value2

        public class IniControlClass
        {
            [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
            public static extern int GetPrivateProfileSectionNames(IntPtr lpszReturnBuffer, uint nSize, string lpFileName);
            [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
            public static extern uint GetPrivateProfileString(string lpAppName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString, int nSize, string lpFileName);
            [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
            public static extern uint GetPrivateProfileString(string lpAppName, string lpKeyName, string lpDefault, [In, Out] char[] lpReturnedString, int nSize, string lpFileName);
            [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
            public static extern int GetPrivateProfileString(string lpAppName, string lpKeyName, string lpDefault, IntPtr lpReturnedString, uint nSize, string lpFileName);
            [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
            public static extern int GetPrivateProfileInt(string lpAppName, string lpKeyName, int lpDefault, string lpFileName);
            [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
            public static extern int GetPrivateProfileSection(string lpAppName, IntPtr lpReturnedString, uint nSize, string lpFileName);
            [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
            public static extern bool WritePrivateProfileString(string lpAppName, string lpKeyName, string lpString, string lpFileName);
        }
  • 相关阅读:
    numpy之填充为nan的数据为该列平均值
    使用Apache HttpClient 4.5设置超时时间
    使用Apache HttpClient 4.x进行异常重试
    使用Apache HttpClient 4.x发送Json数据
    用Maven创建动态Web工程
    Eclipse查看.properties文件中文乱码
    Oracle数据库常用命令(持续更新)
    Spring@PostConstruct注解和构造方法的调用顺序
    在Java中使用Maven配置的版本信息
    Maven profile动态选择配置条件
  • 原文地址:https://www.cnblogs.com/LJP-JumpAndFly/p/5169752.html
Copyright © 2011-2022 走看看