能举个例子吗?
比如我想读取HELLO.INI中的HELLO=你好怎么读取
[HELLO]
HELLO=你好
在比如怎么写入配置项?把你好改成你好吗
还有怎么读取TXT中的内容?

解决方案 »

  1.   

    又是文件读写很简单1,打开MSDN
    2,在索引里输入System.IO
    3,自己边看边学边实践
      

  2.   

    [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 static void writeIni(string section, string key, string value, string filePath)//写配置文件
      {
      WritePrivateProfileString(section, key, value, filePath);
      }
      public static string readIni(string section, string key, string filePath)//读配置文件
      {
      StringBuilder tempBuilder = new StringBuilder(1024);
      int i = GetPrivateProfileString(section, key, "", tempBuilder, 1024, filePath);
      return tempBuilder.ToString();
      }
      

  3.   

    方法有很多,可以调用系统的API如2楼,也可以用C#自己的文件读写类,看你习惯用哪个了。
      

  4.   

    2楼的这是标准的微软INI文件读取方式。也可以自己做文本读写的类,判断“[]”标签即可,很容易的。
      

  5.   

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Runtime.InteropServices;public class IniFile
       {
            //文件INI名称
            //public string Path;        /**/////声明读写INI文件的API函数
            [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);
            //类的构造函数,传递INI文件名
            //public IniFile(string inipath)
            //{
            //    //
            //    // TODO: Add constructor logic here
            //    //
            //    Path = inipath;
            //}        //写INI文件
            public void IniWriteValue(string Section, string Key, string Value,string Path)
            {
                WritePrivateProfileString(Section, Key, Value,Path);
            }        /// <summary>
            /// 读取INI文件指定的文件数据
            /// </summary>
            /// <param name="Section"></param>
            /// <param name="Key"></param>
            /// <param name="Path"></param>
            /// <returns></returns>
            public string IniReadValue(string Section, string Key,string Path)
           {
                StringBuilder temp = new StringBuilder(255);
                int i = GetPrivateProfileString(Section, Key, "", temp, 255, Path);
                return temp.ToString();
            }
            /**//// <summary>
            /// 验证文件是否存在
            /// </summary>
            /// <returns>布尔值 </returns>
            //public bool ExistINIFile()
            //{
            //    return File.Exists(this.Path);
            //}    }//调用测试向INI文件写入数据IniWriteValue("Login Information","Password ","73C18C59A39B3","F:\test.ini");查看INI文件信息[Login Information]
    Password=73C18C59A39B3//读INI文件里的Password值String Password = IniFile.IniReadValue("User Information","Password","F:\test.ini");