if ( ! Directory.Exists (curentpath+"\\kqData\\"+CurrendDate))
{
    Directory.CreateDirectory(curentpath + "\\kqData\\" + CurrendDate);
}string str = curentpath + "\\kqData\\" + CurrendDate + "\\" + CurrendDate + ".txt";using (StreamWriter NewStream = new StreamWriter(curentpath + "\\kqData\\" + CurrendDate + "\\" + CurrendDate + ".txt", true))
{
     NewStream.WriteLine(ss);
     NewStream.Close();
}
你试试吧

解决方案 »

  1.   

    你把创建的代码移动到写入文件代码的同一个事件里面就行
    反正formload只是创建 除此没别的操作
      

  2.   

    if (!File.Exists(curentpath + "\\kqData\\" + CurrendDate + "\\" + CurrendDate + ".txt"))
                 {
                     FileInfo Myfile = new FileInfo(curentpath + "\\kqData\\" + CurrendDate + "\\" + CurrendDate + ".txt");
                     Myfile.Create();
                 
                 }
    去掉 没用
    貌似fi没关闭的?
    sw会自动建
      

  3.   

    找半天close,原来再Create里面...
    还是直接用StreamWriter BinaryWriter方便
      

  4.   

    xmchw(xmchw)其它地方,没有打开文件
    ---------------------------------
    什么意思?
      

  5.   

    你把FileInfo一段去掉  照样可以跑
      

  6.   

    if ( ! Directory.Exists (curentpath+"\\kqData\\"+CurrendDate))
                {
                   Directory.CreateDirectory(curentpath + "\\kqData\\" + CurrendDate);
                 }
                 if (!File.Exists(curentpath + "\\kqData\\" + CurrendDate + "\\" + CurrendDate + ".txt"))
                 {
                     FileInfo Myfile = new FileInfo(curentpath + "\\kqData\\" + CurrendDate + "\\" + CurrendDate + ".txt");
                     Myfile.Create();
                 
                 }
    这些代码都不要了。在你创建NewStream得时候加入参数,让它可以创建文件,好像是FileMode.CreateOrOpen,FileAccess.WriteOrOpen ,你自己看看MSDN吧
      

  7.   

    new FileStream(filename, FileMode.OpenOrCreate, FileAccess.ReadWrite);