在.NET中的System.IO.File下的成员都是Static,可以无需实例化而直接使用:
System.IO.File.Open("C:\autoexec.bat",FileMode,FileAccess)
关于这一点你可以查一下MSDN

解决方案 »

  1.   

    使用FileStream中的ReadLine然后分开[],和=之类的关键字,然后你就会明白了
      

  2.   

    API: WriteProfileString/GetProfileString
    在C#里面可以用RegEx编一个读取Ini的包装——如果有兴趣的话。
      

  3.   

    qqchen79(知秋一叶) (  ) 信誉:100 有代码?
      

  4.   

    Use COM Interop to Read and Write to INI Files with .NET 
    http://www.devx.com/dotnet/discussions/040902/cominterop.asp
      

  5.   

    source code as following:using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Diagnostics;using System.Timers;
    using System.IO ;
    using System.Runtime.InteropServices;  
    using System.Text;
    namespace TestLMS
    {
    /// <summary>
    /// Summary description for Class1.
    /// </summary>
    class Class1
    {
    static void Main(string[] args)
    {
    int int1= Class2.ReadInterval(@"D:\LMS\LMSService\bin\Debug\Interval.ini") ; 
    System.Console.WriteLine(int1.ToString());  
    }

    class Class2
    {

    [DllImport("kernel32.dll")]
    public static extern unit GetPrivateProfileString(
    string lpAppName,        // section name
    string lpKeyName,        // key name
    string lpDefault,        // default string
    StringBuilder lpReturnedString,  // destination buffer
    uint nSize,              // size of destination buffer
    string lpFileName   // initialization file name
    ); public static int ReadInterval(string IniFile)
    {
    try
    {
    string strFileName= IniFile;
    int intBufferSize=10;
    string strSec="Timer";
    string strK="Interval";
    StringBuilder strReturn = new StringBuilder(10); long lngRet=GetPrivateProfileString(strSec,strK,"",strReturn,intBufferSize,strFileName);

    return System.Int32.Parse(strReturn.ToString());
    }
    catch(Exception e)
    {
    System.Console.WriteLine(e.Message);
    System.Diagnostics.EventLog.WriteEntry("LMS","讀取文件 "+ IniFile 
    +" 時出錯.請確保它在正確的目錄中!");
    return 43200;
    }
    }
    }
    }
    }
    ps:
    Interval.ini
    [Timer]
    Interval=1000注意;uint 不可為 long