现在需要将一行一行的文本写入到dat文件,每写一行要换行,要写入的数据是从数据库取出的,
dat文件时自己生成的,还请帮忙,最好有code,谢谢!

解决方案 »

  1.   


            System.IO.StreamWriter sw = null;
            try
            {
                sw = new System.IO.StreamWriter(@"d:\data.dat", true);
                for (int i = 0; i < 10; i++)
                {
                    sw.WriteLine(String.Format("Item {0}.", i));
                }
                sw.Flush();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {            sw.Close();
                sw.Dispose();
            }
      

  2.   

    File.AppendText
    File.WriteAllLines
    StreamWriter
      

  3.   

    WriteLine
      

  4.   

    更 读取记事本是一样的 。
    //生成批处理文件用于重启程序
                    string bat=Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"update.bat");
                    if (File.Exists(bat))
                        File.Delete(bat);
                    using(StreamWriter sw=new StreamWriter(bat,true))
                    {
                        sw.WriteLine("@echo off");
                        sw.WriteLine(":find");
                        FileInfo appexe = new FileInfo(Application.ExecutablePath);
                        sw.WriteLine(string.Format("tasklist|find \"{0}\" ||goto next", appexe.Name));
                        sw.WriteLine("goto find");
                        sw.WriteLine(":next");
                        foreach (string name in okfiles)
                        {
                             sw.WriteLine(string.Format("copy update\\{0} {1} /y",name,name));
                        }
                        sw.WriteLine("start "+Application.ExecutablePath);
                        sw.WriteLine("del %0");
                        sw.WriteLine("exit");
                    }
                    System.Diagnostics.Process.Start(bat);
                    Environment.Exit(0);