列入:
  我的(*.txt)或(*.fig)中的内容有:
  database = master
  uis = sa
  pwd = aa 我在程序中怎么去读取这些对应的值哦 ???

解决方案 »

  1.   

    StreamReader reader  = new StreamReader("xx.txt");
    string data;
    while((data=reader.Read())!=null)
    {
        Console.WriteLine(data);//这样可以输出文件每一行
    }
      

  2.   

    如果还要取出等号后面的值。这样:
    StreamReader reader  = new StreamReader("xx.txt"); 
    string data; 
    while((data=reader.Read())!=null) 

        Console.WriteLine(data.Split('=')[1]);//Split按等号拆分成一个字符串数组 
    }
      

  3.   

    也可通过API函数GetPrivateProfileString等实现操作
    http://www.cnblogs.com/tianxiao/articles/1209300.html
    http://www.cnblogs.com/inuli/archive/2008/12/29/1364542.html
      

  4.   

    2楼正解、用StreamReader去读文档就O了...不止是txt和fig格式的...ini、XML等格式也都能读到
      

  5.   

    楼上几位大哥,人家问的是—— 
    我在程序中怎么去读取 
      database = master
      uis = sa
      pwd = aa
    这些对应的值哦 ???
    不是问的怎么读这文档。OMG,答问题的时候,感情大家都不看完就答啊。晕。
      

  6.   

    StreamReader什么都能读
    在sr.ReadLine的时候判断或者更好的方案是:
    用StreamReader将数据读入xml或者DataSet,就能使用Linq或者Sql来检索数据了
      

  7.   

    [DllImport("kernel32")]
            private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal,
                                                              int size, string filePath);
            /// <summary>
            /// 获取文件中指定节点对应值
            /// </summary>
            /// <param name="projectName">项目名</param>
            /// <param name="key">节点名</param>
            /// <param name="filePath">文件路径</param>
            /// <returns></returns>
            public string ReadValue(string projectName, string key, string filePath)
            {
                var temp = new StringBuilder(500);
                int i = GetPrivateProfileString(projectName, key, "", temp, 500, filePath).ToString();
                return temp.ToString();
            }然后你txt文件中内容的格式特定一下[projectName]
    key=value
    key1=value
    也就是
    [connectionstrings]
    database = master
    uis = sa
    pwd = aa
    [DllImport("kernel32")]这是引用名为kernel32的动态类库
    private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal,
                                                              int size, string filePath);
    是该类库中的一个方法
      

  8.   

    还有忘说了...
    记得引用一下using System.Runtime.InteropServices;
      

  9.   

    ReadFile
    然后根据正则表达式一一获取即可
    你这个问题可以先按行读取,然后string.split(" = ");
    然后拿偶数个string就是你想要的值
      

  10.   

    利用System.IO下的StreamReader读取
    首先引入命名空间System.IO;FileStream fs = new FileStream("路径",FileMode枚举类型的值(设定操作文件的方式));
    StreamReader sr = new StreamReader(fs);
    string content;
    while((content = sr.ReadLine()) != null)
    {
      Console.Write(content);
    }sr.Close();
    fs.Close();
      

  11.   

    StreamWriter sw = new StreamWriter(asFDFile, true, Encoding.GetEncoding(piEncodingFormat));
    //asFDFile  文件名//piEncodingFormat 编码