zoukankan      html  css  js  c++  java
  • C# 读写 Ini 文件

    using System.Runtime.InteropServices;
    public class IniFile
    {
        
    private string path;

        
    public IniFile(string iniPath)
        {
            
    this.path = iniPath;
        }

        [DllImport(
    "kernel32")]
        
    private static extern int GetPrivateProfileString
            (
    string section, string key, string def, StringBuilder retVal, int size, string filePath);
        [DllImport(
    "kernel32")]
        
    private static extern long WritePrivateProfileString
            (
    string section, string key, string val, string filePath);

        
    public string IniReadValue(string section, string key)
        {
            
    try
            {
                StringBuilder retVal 
    = new StringBuilder(0xff);
                
    if (GetPrivateProfileString(section, key, "", retVal, 0xffthis.path) == 0)
                {
                    
    return string.Empty;
                }
                
    return retVal.ToString();
            }
            
    catch (Exception exception)
            {
                
    return exception.ToString();
            }
        }

        
    public void IniWriteValue(string Section, string Key, string Value)
        {
            WritePrivateProfileString(Section, Key, Value, 
    this.path);
        }
    }
  • 相关阅读:
    putty配色方案
    LDAP
    cmder显示UTF-8字体
    CentOS Linux release 7.2.1511 (Core)
    扩展欧几里得算法
    Chinese remainder theorem
    弹琴吧
    RSA DH
    iOS 和 Android 的后台推送原理各是什么?有什么区别?
    Codelite安装详解
  • 原文地址:https://www.cnblogs.com/anjou/p/1584715.html
Copyright © 2011-2022 走看看