上面我写的太多了,这部分是主要的:                
{
                    SaveFileDialog sf = new SaveFileDialog();
                    sf.Title = "保存文件";
                    sf.Filter = "txt文件|*.txt|所有文件|*.*";//将计算结果保存为txt类型
                    if (sf.ShowDialog() == DialogResult.OK)
                    {
                        FileStream fs = new FileStream(sf.FileName, FileMode.Create);
                        StreamWriter sw = new StreamWriter(fs);
                        string[] tempStr = new string[3];
                        tempStr[0] = 待定点名.Text;
                        tempStr[1] = Convert.ToString(待定点X.Text);
                        tempStr[2] = Convert.ToString(待定点Y.Text);
                        for (int i = 0; i < tempStr.Length; i++)
                        {
                            if (i > 0)
                            {
                                sw.Write(",");
                            }
                            sw.Write(tempStr[i]);
                        }
                        sw.Flush();
                        sw.Close();
                        fs.Close();
                    }
                }

解决方案 »

  1.   

    用AppendText就可以追加的。using System;
    using System.IO;class Test 
    {
        
        public static void Main() 
        {
            FileInfo fi = new FileInfo(@"c:\temp\MyTest.txt");        // This text is added only once to the file.
            if (!fi.Exists) 
            {
                //Create a file to write to.
                using (StreamWriter sw = fi.CreateText()) 
                {
                    sw.WriteLine("Hello");
                    sw.WriteLine("And");
                    sw.WriteLine("Welcome");
                }    
            }        // This text will always be added, making the file longer over time
            // if it is not deleted.
            using (StreamWriter sw = fi.AppendText()) 
            {
                sw.WriteLine("This");
                sw.WriteLine("is Extra");
                sw.WriteLine("Text");
            }            //Open the file to read from.
            using (StreamReader sr = fi.OpenText()) 
            {
                string s = "";
                while ((s = sr.ReadLine()) != null) 
                {
                    Console.WriteLine(s);
                }
            }
        }
    }
      

  2.   

    创建文件流时有几种模式供选择
    Create,CreateNew,Append之类的,对你要的写入分别选择合适的模式即可实现清空原有文件写入和在原有文件进行追加