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);
        }
  • 相关阅读:
    Sql优化(二) 快速计算Distinct Count
    Minor GC和Full GC区别(转)
    对于JVM中方法区,永久代,元空间以及字符串常量池的迁移和string.intern方法
    2017/6/29杂记
    java中代理,静态代理,动态代理以及spring aop代理方式,实现原理统一汇总
    ThreadLocal的设计理念与作用
    2017/6/28杂记
    关于hashmap 与concurrentHashMap
    2017/6/27杂记
    深入理解java异常处理机制
  • 原文地址:https://www.cnblogs.com/LJP-JumpAndFly/p/5169752.html
Copyright © 2011-2022 走看看