string  strPath="E:\WebApplication\abc.txt";  
FileInfo  fi=new  FileInfo(@strPath);  
if(!fi.Exists)  
{  
           FileStream fs = fi.Create();  
fs.Close();
}  
StreamWriter  sw=fi.AppendText();  
sw.WriteLine();  
sw.WriteLine(DateTime.Now.ToString());  
sw.Close();

解决方案 »

  1.   

    其实这样就可以了:
    string  strPath="E:\WebApplication\abc.txt";
    StreamWriter  sw=new StreamWriter(strPath,true);  
    sw.WriteLine();  
    sw.WriteLine(DateTime.Now.ToString());  
    sw.Close();
      

  2.   

    if(!fi.Exists)  
    {  
               sw = fi.Create();  
    }  
    else
    sw=fi.AppendText();
      

  3.   

    StreamWriter sw;
    if(!fi.Exists)  
    {  
       sw = fi.Create();  
    }  
    else
       sw = fi.AppendText();
      

  4.   

    StreamWriter  sw;
    if(!fi.Exists)  
    {  
       sw = fi.Create();  
    }  
    else
       sw = fi.AppendText();
      

  5.   

    string  strPath="E:\WebApplication\abc.txt"; 介个没有报错?
    这样才对吧:
    string  strPath=@"E:\WebApplication\abc.txt";
      

  6.   

    string  strPath="E:\\WebApplication\\abc.txt"; 这样没问题
      

  7.   

    if(!fi.Exists)  
    {  
               fi.Create();  
    }  根本不需要StreamWriter  sw=fi.AppendText();  
    会自动检测的,没有就创建,有就追加
      

  8.   

    string strPath=@"E:\WebApplication\abc.txt";
    StreamWriter sw=new StreamWriter(strPath,true);
    sw.WriteLine();
    sw.WriteLine(DateTime.Now.ToString());
    sw.Close();